You are here: Re: php generated table lists problems. « PHP Programming Language « IT news, forums, messages
Re: php generated table lists problems.

Posted by Advo on 12/13/06 20:01

SBGamesCone wrote:
> 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?

hey, thanks for the prompt reply. $j is nothing, i was testing before
hand.
In the for loop i changed from:

for ($i = 0;$i< 5; $i++) {

to

for ($i = 0;$i< $number_of_total_rows; $i++) {

the code works, but the products still go across the page for eternity,
rather than cutting off after 5 products, then going to the next row if
that makes any sense.

any ideas?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация