Newbie: Silly Splitting Results Issue
Posted: Mon Dec 20, 2004 5:09 am
Hello everybody!
I'm new round these parts, and to PHP, so be gentle. Anyway....
I'm trying to split my mySQL results from my database table so that, not un-similar to a certain large online retail Co., I have a four-column display with the image in the one row and a description in the row below. E.g. the first table row would be something like: image1, image2, image3, image4. Then the next row would be description1, description2, description3 and description4. Get the idea?
I can successfully output my results in to a four-column table but not the image/description separation part. If any one is still reading and could give me a point in the direction I should be going I would be most grateful.
Here is what I have so far:
I'm new round these parts, and to PHP, so be gentle. Anyway....
I'm trying to split my mySQL results from my database table so that, not un-similar to a certain large online retail Co., I have a four-column display with the image in the one row and a description in the row below. E.g. the first table row would be something like: image1, image2, image3, image4. Then the next row would be description1, description2, description3 and description4. Get the idea?
I can successfully output my results in to a four-column table but not the image/description separation part. If any one is still reading and could give me a point in the direction I should be going I would be most grateful.
Here is what I have so far:
Code: Select all
<?php
mysql_connect($db_host, $db_user, $db_password,$db_name) or
die("Could not connect: " . mysql_error());
mysql_select_db("prod_test");
$result = mysql_query("SELECT * FROM products");
$num_rows = mysql_num_rows($result);
$i = 0;
echo "<table>"; //open items table
// start output
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
if ($i%4==0)
{
echo "<tr>";
}
echo("<td>".$rowї'sku']."</td>");
$i++;
if($i%4==0)
{
echo "</tr>";
}
}
echo "</table>"; //close items table
echo "Number of records ".$num_rows."<br>";
mysql_free_result($result); //end sql statment and free memory
?>