Need products to show in grid instead of a row on php page

Codes here !

Moderators: egami, macek, gesf

Post Reply

Sat Jun 23, 2012 12:28 pm

OK so I have been following some external tutorials for creating a website based around php which is great for what I am trying to accomplish. But i have hit a sticking point with some code. So far I have all my tables built, entries in the tables and such but on my main php page I can only get the results to render out in rows only instead of a grid (would like if I can 3x4).

My current coding for the php scripting is below, this is called on in the HTML code by <?php echo $dynamicList; ?>

Code: Select all

// run a select query to get the latest 6 items
include "storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysql_num_rows ($sql); // count the output amount
if ($productCount > 0){
	while($row = mysql_fetch_array($sql)){
		$id = $row["id"];
		$sku = $row["sku"];
		$product_name = $row["product_name"];
		$price = $row["price"];
		$dynamicList .= 
		'<table width="100" border="0" cellpadding="3">
  	     	 <td align="left" valign="top"><a href="product.php?id=' .$id. '"><img src="inventory_images/' .$id. '.jpg" alt="$product_name" width="125" border="0"/></a>
          	 <td align="left" valign="top">' .$product_name. '</td>
          	 <td align="left" valign="top">£' .$price. '</td>
} else {
	$dynamicList = "You have no products listed in our store yet"	;
Basically what I would really like is for the coding to render the next table to the right of the last until they reach 3 tables, then go down to the next row. The overall outcome I want this coding to complete is to show multiple products in a grid format which name and price shown beneath each photo

Thanks in advance

Post Reply