473,799 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_catego ry_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\ ">$imagenam e</tr>";
echo "<tr align=\"center\ ">$descript ion</tr>";
echo "<tr align=\"center\ "><td collspan='3'&nb sp;</td></tr>";
echo "</table>";

Dec 13 '06 #1
3 1277


On Dec 13, 11:02 am, "Advo" <max_misch...@h otmail.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_categor y_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\ ">$imagenam e</tr>";
echo "<tr align=\"center\ ">$descript ion</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_catego ry_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\ ">$imagenam e</tr>";
echo "<tr align=\"center\ ">$descript ion</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...@h otmail.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_categor y_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\ ">$imagenam e</tr>";
echo "<tr align=\"center\ ">$descript ion</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_catego ry_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\ ">$imagenam e</tr>";
echo "<tr align=\"center\ ">$descript ion</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_tota l_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_categor y_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\ ">$imagenam e</tr>";
echo "<tr align=\"center\ ">$descript ion</tr>";
echo "<tr align=\"center\ "><td collspan='3'&nb sp;</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_ca tegory_name); $i++) {
if (($i % 5) && ($name <'')) { // Every 5th line except first
echo "<tr align=\"center\ ">$name</tr>\n";
echo "<tr align=\"center\ ">$imagenam e</tr>\n";
echo "<tr align=\"center\ ">$descript ion</tr>\n";
$name = $imagename = $description = '';
}
$name .= '<td style="padding-bottom: 3px;">'.
$array_category _name[$i] . '</td>';
$imagename .= '<td>'.
'<img src="images/'.$array_catego ry_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_ca tegory_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\ ">$imagenam e</tr>\n";
echo "<tr align=\"center\ ">$descript ion</tr>\n";
}
echo "</table>";

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 14 '06 #4

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

Similar topics

0
8418
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: '@localhost' to database 'test1' Any help would be appreciated
0
3330
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 the master is down? Also will this create problems when the master comes back and the slave copies updates from the master log file? application/web server
0
631
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 could that cause something like this? # myisamchk -c jobs Checking MyISAM file: jobs Data records: 53484 Deleted blocks: 37182 myisamchk: warning: Table is marked as crashed - check file-size
0
1612
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 the problems by upgrading to mysql 4.0.14, putting the database that I needed absolute best performance on a fast scsi drive all by itself. Then twice this week I needed to add a column to a large table (about a million records). The tables...
61
24510
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 'stretch'</td> <td valign="top" width="300">some data that won't 'stetch'</td> </tr> </table>
0
3556
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 usually styled something like: ] Term ] A tab of white space followed by the definition ] By
2
11558
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 with identity column also, (so if i use generated as always, i can't do insert into new_tables select * from old_table), then i might also insert new data into this new table (if i do generated by default, then the new table could have the same...
2
1452
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 Versions Version Comparison Using Your Computer
4
1743
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 Statements for primary key on Table "SCHEMA1 "."X2"
0
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.