473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

php generated table lists problems.

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'&nbsp;</td></tr>";
echo "</table>";

Dec 13 '06 #1
3 1253


On Dec 13, 11:02 am, "Advo" <max_misch...@hotmail.comwrote:
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?

Dec 13 '06 #2

SBGamesCone wrote:
On Dec 13, 11:02 am, "Advo" <max_misch...@hotmail.comwrote:
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?

Dec 14 '06 #3
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'&nbsp;</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>&nbsp;</td>\n";
$imagename .= "<td>&nbsp;</td>\n";
$description .= "<td>&nbsp;</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
==================
Dec 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Didier ROS | last post by:
Hi, I am a newbie I want to create a temporary table and I get the following error message : mysql> CREATE TEMPORARY TABLE tempemp AS SELECT * FROM emp; ERROR 1044: Access denied for user:...
0
by: nm | last post by:
Is it possible to MERGE innodb tables? Can't find docs on mysql.com In replication. I guess I can update the slave if the master is not responding, right? Shall I 'stop slave' before , in case...
0
by: Stephen Crowley | last post by:
Are there any known issues with table corrouption on 4.0.14-standard-log? I'm getting recurring problems with a single table becoming corrupted, does mysql handle disk full problems gracefully or...
0
by: Dan Edwards | last post by:
Hi about 2 months ago I had trouble with alter table on large tables blocking all database activity and started a thread on this list called "alter table blocks other tables!" I tried to resolve...
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
0
by: Jimmy Cerra | last post by:
I recently came up with a cool little stylesheet for definition lists. There is a small demostration for the impatient . I hope this helps someone. Here's how I did it. Definition lists are...
2
by: db2group88 | last post by:
i would like to know when i create a table with identity column, should i used generated by default or generated as always. since when i create this table, i might copy some data from another table...
2
by: David Trimboli | last post by:
I'm trying to figure out which makes the most semantic sense for a Table of Contents. Here is a sample of the ToC (each line is a link to a document): Windows Operating System Supported...
4
by: Bernard Dhooghe | last post by:
Table definition: CREATE TABLE "SCHEMA1 "."X2" ( "C1" CHAR(20) NOT NULL , "C2" CHAR(10) NOT NULL , "C3" CHAR(30) NOT NULL GENERATED ALWAYS AS (C1|| C2) ) IN "USERSPACE1" ; -- DDL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.