----- Original Message -----
From: Adv. Systems Design <[EMAIL PROTECTED]>
To: PHP List <[EMAIL PROTECTED]>
Sent: Friday, September 14, 2001 12:09 AM
Subject: [PHP-DB] Table display Driving me Crazy!
> Hello *
> trying to output mysql content into a table, but the
> table is designed to use 3 Trows to display info for
> ONE product (table also has to have 5 columns):
> row1 sku1|sku2|sku3|sku4|sku5
> row2 img1|img2|img3|img4|img5
> row3 nam1|nam2|nam3|nam4|nam5
> ---------------------------------
> row4 sku6|sku7|sku8|sku9|sku10
> row5 img6|img7|img8|img9|img10
> row6 nam6|nam7|nam8|nam9|nam10
> ---------------------------------
> etc...
> I have code that is displaying the right #of columns
> but it is simply repeating the product across the
> table...
>
> <table width="100%" border="1" cellspacing="0"
> cellpadding="0" bgcolor="#000000">
> <?php
> $db->query($list);
> while ($db->next_record()) { ?>
> <tr bgcolor="#666666">
> <?php $numcols = 5;
> for ($l = 1; $l <= $numcols; ++$l) {?>
> <td width="139" class="ModNo"
> bordercolor="#000000"><?php echo
> $db->f("product_sku"); ?></td>
> <?php } ?>
> </tr>
> <tr bgcolor="#ECEF7A">
> <?php for ($l = 1; $l <= $numcols; ++$l) { ?>
> <td height="80" bordercolor="#000000">
> <div align="center"><A HREF="<?php
> $sess->purl(URL . "?page=$flypage&product_id=" .
> $db->f("product_id") . "&category_id=" .
> $db->f("category_id")); ?>">
> <?php
> $ps_product->show_image($db->f("product_thumb_image"),"");
> ?></A>
> </div>
> </td>
> <?php } ?>
> </tr>
> <tr bgcolor="#C9C62D" bordercolor="#C9C62D">
> <?php for ($l = 1; $l <= $numcols; ++$l) { ?>
> <td class="prodName"><?php
> $db->p("product_name"); ?></td>
> <?php } ?>
> </tr>
> <?php } ?>
> </table>
>
> Anybody have any ideas how I can get this thing to
> work?!
Looking at your code for the first row (I've cleaned it up a bit to make it
readable!):
<?php
$numcols = 5;
for ($l = 1; $l <= $numcols; ++$l) {
?>
<td width="139" class="ModNo" bordercolor="#000000">
<?php
echo $db->f("product_sku");
?>
</td>
<?php
}
?>
It should be pretty clear why you're getting the product just repeated 5
times across the row.
Your statement:
echo $db->f("product_sku");
does not contain any reference to variables thus it's essentially a
constant.
As far as I can make out (your style of coding gives me a headache :)) the
other loops suffer from the same problem.
If you find yourself often mixing php with html then using the alternative
syntax for constructing loops makes the code simpler and clearer (see
http://www.php.net/manual/en/control-structures.for.php).
Also if your particular php setup allows using <? ?> instead of <?php ?> to
enclose php code looks cleaner.
For example the above can be rewritten as:
<? $numcols = 5; ?>
<? for ($l = 1; $l <= $numcols; ++$l): ?>
<td width="139" class="ModNo" bordercolor="#000000">
<? echo $db->f("product_sku"); ?>
</td>
<? endfor; ?>
hth
--
Jason Wong
Gremlins Associates
www.gremlins.com.hk
Tel: +852-2573-5033
Fax: +852-2573-5851
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]