By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,405 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,405 IT Pros & Developers. It's quick & easy.

How do I return 3 results and print </tr>

P: n/a
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>
###############

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
*** Aaron Reimann wrote/escribió (31 May 2005 07:55:35 -0700):
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.


$position=0;

while( ... ){
if($position==0){
echo '<tr>';
}

echo '<td>' . $data . '</td>';

if($position==2){
echo '</tr>';
}

$position=($position+1) % 3;
}
We leave completing last line as an exercise for the reader ;-)

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2

P: n/a
"Aaron Reimann" <aa***********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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?

Try something like this:

echo "<tr>";
for ($i = 0; $i < pg_numrows($r); $i++) {
echo "<td>";
// output your info here
echo "</td>";
if ( ( $i + 1 ) % 3 == 0 ) { echo "</tr><tr>"; }
}
echo "</tr>";


Jul 17 '05 #3

P: n/a
Try something like this:

echo "<tr>";
for ($i = 0; $i < pg_numrows($r); $i++) {
echo "<td>";
// output your info here
echo "</td>";
if ( ( $i + 1 ) % 3 == 0 ) { echo "</tr><tr>"; }
}
echo "</tr>";


Thank you. That works for me.

Sorry about the late reply.

Jul 17 '05 #4

P: n/a

"Aaron Reimann" <aa***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Try something like this:

echo "<tr>";
for ($i = 0; $i < pg_numrows($r); $i++) {
echo "<td>";
// output your info here
echo "</td>";
if ( ( $i + 1 ) % 3 == 0 ) { echo "</tr><tr>"; }
}
echo "</tr>";


Thank you. That works for me.

Sorry about the late reply.


Glad I could help :)
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.