I am trying to build a table using results from a database query.
Right now (code below), the code displays each result in a new <tr>. I
am wanted to display 3 results in one <tr> </tr>, and then create a new
<tr> with another 3, etc.
Here is human code:
print a <tr>
if only 1, 2 or 3 results have been returned, show the results and
print a </tr>
if 4, 5, and or 6 results have been returned, print <tr> and show
results
if no more results have been returned, print </tr>
Does that make sense? Can anyone help?
Thank you
Here is my PG query (function):
###############
function section_get_sections() {
$dbconn = sys_db_connect();
if ($dbconn == FALSE) {
return NULL;
}
$dbquery = <<<EOB
SELECT section.id, section.name
FROM section
ORDER BY section.name
EOB;
$dbresult = sys_db_query ($dbconn, $dbquery);
if ($dbresult == FALSE) {
return NULL;
} else {
return $dbresult;
}
}
###############
Here is my PHP current code displaying the results:
###############
EOB;
$r = section_get_sections();
for ($i = 0; $i < pg_numrows($r); $i++) {
$t = pg_fetch_assoc($r, $i);
print <<<EOB
<tr>
<td class="fe_label" nowrap>
{$t['name']}
</td>
<td class="fe_widget">
<input name="sections[]" type="checkbox" value="{$t['id']}"
EOB;
if (in_array($t['id'], $fd['sections'])) {
echo(" checked");
}
print <<<EOB
</td>
</tr>
###############