I need help displaying some products from a mysql database in a 3x4 table or what ever size i choose to do. An example of how I want to display it is http://www.golfcircuit.com/Golf-Drivers/13__.html. Right now I just have it displaying in a n x 1 format. Like so http://webdev.cs.kent.edu/~jfunchio/wp2/HW2/index.php. I will be changing the how my products are displayed so just the title is above the product in a square exactly like the golfcircuit site. I just need help how to dynmicaly display the products like that. My code is below.

<?php 

error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
session_start(); 

// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['username'])) {
    // Put stored session variables into local php variable
    $userid = $_SESSION['id'];
    $username = $_SESSION['username'];
    $toplinks =  $username . '</a> • 
    <a href="member_account.php">Account</a> • 
    <a href="logout.php">Log Out</a> •
    <a href="cart.php">Cart</a>';
} else {
    $toplinks = '<a href="index.php">Home</a> • <a href="user_register.php">Register</a> • <a href="user_login.php">Login</a>';
}

?>
<?php 
// Run a select query to get my letest 6 items
// Connect to the MySQL database  
include "connect_to_mysql.php"; 
$dynamicList = "";
$query = "SELECT * FROM product ORDER BY date_added DESC LIMIT 6";
$result = $db_obj->query($query);
$productCount = $result->num_rows; // count the output amount
if ($productCount > 0) {
    while($row = $result->fetch_array(MYSQLI_ASSOC)){ 
             $id = $row["id"];
             $product_name = $row["product_name"];
             $price = $row["price"];
             $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
             $dynamicList .= '<table width="50%" border="1" cellspacing="3" cellpadding="5">
        <tr>
          <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a>
          ' . $product_name . '<br />
            $' . $price . '<br />
            <a href="product.php?id=' . $id . '">View Product Details</a></td>
        </tr>
      </table>';
    }
} else {
    $dynamicList = "We have no products listed in our store yet";
}

$result->close();
$db_obj->close();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Store Home Page</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainWrapper">
  <?php //include_once("template_header.php");
   echo $toplinks; 

  ?>
  <div id="pageContent">
  <table width="100%" border="0" cellspacing="0" cellpadding="10">
  <tr>

    <td width="35%" valign="top"><h3>Latest Designer Fashions</h3>
      <p><?php echo $dynamicList; ?><br />
        </p>
      <p><br />
      </p></td></tr>


</table>

  </div>
  <?php include_once("template_footer.php");?>
</div>
</body>
</html>

You'll find examples of this in this forum. Just try a search first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.