In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
says...
> Hello,
>
> I am trying to display a HTML table of 2 cells with "n" elements... This means
> an unknown number of lines.
>
> I need to use 2 FOR loops (one to determine the number of <TR> and one to
> create the 2 cells needed). This is a bit to overwellming for me...
>
> I have:
>
> $result = connect_db("select prod_id,photo from prod where cat_id=1");
> $Rows = pg_NumRows($result);
> $lines_TOT = ceil($Rows/2);
>
>
> for($TR=0; $TR < $ligne_TOT; $TR++){
> print "<tr>\n";
>
> for($TD=0; $TD < 2;$TD++){
> $photo=pg_Result($result,$TD,photo);
> $prod_id=pg_Result($result,$TD,prod_id);
> print "<td>";
> if ($prod_id != ""){
> print "<img src=\"../photo/". $photo. "s.jpg\" border=0>\n";
> } else {
> print " ";
> }
> print "</td>";
> }
> }
>
>
> As you can see, the second loop cant continue to display the next product... So
> the first line with the 2 images are ok but the other lines are identical, so
> if I have 10 products, I see only 1 and 2 over 5 lines!
>
> How can I solve this? To have 2 columns per line, I must limit the loop but I
> need to continue at that point on the second line...
>
> Thank you for any assistance!
>
What about something like:
<TABLE><TR>
<?php
$i = 1; // This is counter for number of records processed
$items = 2; // how many cells per row
$result = connect_db("select prod_id,photo from prod where cat_id=1");
while($row = pg_fetch_array($result, PGSQL_ASSOC)) {
extract($row);
if($i % $items == 0) {
echo '</TR><TR>';
}
echo '<TD><img src="../photo/'. $photo. 's.jpg" border=0></TD>\n";
$i++;
}
?>
</TR></TABLE>
Uses the modulus operator to keep track of how many rosws/columns you
have. Untested, of course.
--
David Robley
Temporary Kiwi!
Quod subigo farinam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php