Advo 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>";
First of all, do you want one table with many rows, or many tables?
Your code (if it worked properly) would create many tables (the <table
statement is within your loop).
Assuming you want one table with multiple rows, there are several ways
to do it. The easiest is probably to just add a new row every time you
get another 5 items (warning - not tried, may contain syntax errors!):
echo '<table width="100%" border="0" align="center" ' .
'cellpadding="0"' cellspacing="0">';
$name = $imagename = $description = '';
// Assuming all arrays have the same # of elements
for ($i = 0;$i count($array_category_name); $i++) {
if (($i % 5) && ($name <'')) { // Every 5th line except first
echo "<tr align=\"center\">$name</tr>\n";
echo "<tr align=\"center\">$imagename</tr>\n";
echo "<tr align=\"center\">$description</tr>\n";
$name = $imagename = $description = '';
}
$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>';
}
// Might have a partial last rows) - complete them
for ($i = count($array_category_names); $i % 5 0; $i++)
$name .= "<td> </td>\n";
$imagename .= "<td> </td>\n";
$description .= "<td> </td>\n";
}
if ($name <'') { // If something left in it
echo "<tr align=\"center\">$name</tr>\n";
echo "<tr align=\"center\">$imagename</tr>\n";
echo "<tr align=\"center\">$description</tr>\n";
}
echo "</table>";
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================