tabular data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

tabular data

Post by aceconcepts »

Hi,

I am trying to display a list of products in a table. The code below displays data from a mysql database row-by-row.

However, I would like to be able to display the products row-by-row but instead of displaying one product per row i would like to display more than one product per row.

Here is the code i currently use to display row-by-row data:

Code: Select all

<?php
//include "auth.inc.php";
//include "b2b_header.php";
//CONNECT TO SERVER AND DATABASE
include "conn.inc.php";

$query = "SELECT * FROM product" ;

$result = mysql_query($query)
	or die(mysql_error());
?>
<html>
<head>
<title>Product List</title>
</head>
<body>
<table>
<tr>
	<td width="10%">Product Code</td>
	<td width="20%">Name</td>
	<td width="20%">Description</td>
	<td width="30%">Image</td>
	<td width="10%">Price</td>
	<td width="10%">Stock</td>
</tr>
<?php
while ($row = mysql_fetch_array($result)) {
	extract($row);
	echo "<tr><td width=\"10%\">";
	echo $prod_code;
	echo "</td><td width=\"20%\">";
	echo $prod_name;
	echo "</td><td width=\"20%\">";
	echo $prod_description;
	echo "</td><td width=\"30%\">";
	echo $prod_image;
	echo "</td><td width=\"10%\">";
	echo $prod_unit_price;
	echo "</td><td width=\"10%\">";
	echo $prod_stock_qty;
	echo "</td></tr>";
}
?>
</table>
</body>
</html>
Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Although I don't recommend it in this case due to how you've built the display thus far, but that's not my problem...
Useful Posts wrote:• Multi-column formatted output: PHP & MySQL formatting problem
• Multi-column formatted output 2: Create Member Directory with Alphabetical Listings
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Reading the Useful Post thread helps ;)

#1 and #2
Post Reply