|
Posted by SBGamesCone on 12/13/06 18:31
On Dec 13, 11:02 am, "Advo" <max_misch...@hotmail.com> wrote:
> Hi there.
>
> Im trying to generate a table and its content from a database, and
> display it 5 products across, and as many rows as it needs down.
>
> Ive kind of done this, but the products are being listed like:
>
> Name Name Name Name Name Name Name Name Name Name
>
> Image Image Image Image Image Image Image Image Image Image
>
> descr descr descr descr descr descr descr descr descr descr descr
>
> so theyre going across the page for ever and ever, rather than
>
> Name Name Name Name Name
>
> Image Image Image Image Image
>
> Descr Descr Descr Descr Descr
>
> Name Name Name Name Name
>
> Image Image Image Image Image
>
> Descr Descr Descr Descr Descr
>
> if that makes sense. Any ideas please, im pretty stuck. The code is:
>
> for ($i = 0;$i< 5; $i++) {
> $j++;
>
> $name .= '<td style="padding-bottom: 3px;">'.
> $array_category_name[$i] . '</td>';
> $imagename .= '<td>'. '<img src="images/'
> .$array_category_image_name[$i] . '" width="74" height="59">' .
> '</td>';
> $description .= '<td>'. $array_category_description[$i] . '</td>';
>
> }
> echo '<table width="100%" border="0" align="center" cellpadding="0"
> cellspacing="0">';
> echo "<tr align=\"center\">$name</tr>";
> echo "<br>";
> echo "<tr align=\"center\">$imagename</tr>";
> echo "<tr align=\"center\">$description</tr>";
> echo "<tr align=\"center\"><td collspan='3' </td></tr>";
> echo "</table>";
I cleaned up the code a little bit, but I would first initialize the
variables before the for loop. You are adding data to them without
ensuring they are empty first. Try this:
unset($name, $imagename, $description);
for ($i = 0;$i< 5; $i++) {
$j++;
$name .= '<td style="padding-bottom:
3px;">'.$array_category_name[$i].'</td>';
$imagename .= '<td><img
src="images/'.$array_category_image_name[$i] . '" width="74"
height="59"></td>';
$description .= '<td>'. $array_category_description[$i] . '</td>';
}
echo '<table width="100%" border="0" align="center" cellpadding="0"
cellspacing="0">';
echo "<tr align=\"center\">$name</tr>";
echo "<br>";
echo "<tr align=\"center\">$imagename</tr>";
echo "<tr align=\"center\">$description</tr>";
echo "<tr align=\"center\"><td collspan='3' </td></tr>";
echo "</table>";
Also, what is the point of $j?
Navigation:
[Reply to this message]
|