Help inserting MySql/php Content into div's instead of tables


New poster here.
I’m trying to output the $dynamicList into divs instead of a table.

I’ve seen similar examples and hope someone show me the way.
It’d personally be helpful and would possibly be another great example for someone in a similar position in the future.

Btw, I am sure the code and methodology is outdated and probably not the best as a whole.
This is a tutorial and I am trying to fuse practice and application.

Any help would be awesome.

// Script Error Reporting
ini_set('display_errors', '1');
// Run a select query to get my letest 4 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 4");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
	while($row = mysql_fetch_array($sql)){
             $id = $row["id"];
			 $product_name = $row["product_name"];
			 $price = $row["price"];
			 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
  			 $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
            <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></td>
            <td width="83%" valign="top">' . $product_name . '<br />
              $' . $price . '<br />
              <a href="product.php?id=' . $id . '">View Product Details</a></td>
} else {
	$dynamicList = "We have no products listed in our store yet";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Shop</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
<div align="center" id="mainWrapper">
  <?php include_once("template_header.php");?>
  <div id="pageContent">
  <table width="85%" border="0" cellspacing="0" cellpadding="0">
    <td width="14%" valign="top"><h3></h3>
      <p><br />
        <br />
    <td width="66%" align="center">
        <h3>The Shop </h3>
      <p><?php echo $dynamicList; ?><br />
      <p><br />
    <td width="20%" valign="top"><h3></h3>

  <?php include_once("template_footer.php");?>

Btw, I am sure the code and methodology is outdated and probably not the best as a whole.

You would be well advised to use SQLi or PDO instead of the old SQL, it won’t be around forever:-
As for the main question, I’m not really sure what result you want. It may be easier for you to think of it as just plain old html, and just substitute anything that alters to PHP variables.

I’m really not sure what you’re asking either…if you want to print them to div rather than tables, just replace the tables with divs.

I’m guessing it’s about achieving a certain layout for the data. That would be more about CSS than PHP. PHP/SQL is just supplying the data. HTML and CSS should take care of the layout.
Your use of various HTML tags seems kind of erratic.
If you can work out how you would achieve the desired layout with only html and CSS, you are well on the way. Then it’s just a case of inserting the PHP variables.

BTW, you don’t put a table inside <p></p> tags.

BTW, you don’t put a table inside <p></p> tags.

That’s what I meant about the tags being erratic. There are <p>'s <br/>'s all over the place and <table>'s within <table>'s, is knd of mixed up.
So I think our ‘neub’ needs to learn about a more ordered use of html tags and the use of css for layout.
Then it’s just putting the php variables in the right spot.