Firstly, Please bare in mind that i am a PHP beginner!
I am trying to show all products in a database with a certain catagory in a HTML table. However i'm not sure how to limit the table to 3 columns only.
Here is my code:
<table>
<?php
$catagory=$_GET["q"];
$con = mysql_connect("localhost","cl49-XXX","XXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cl49-XXX", $con)or die( "Unable to select database");
$result=mysql_query("SELECT * FROM products WHERE catagory = '$catagory' ")or die('You need enter a catagory ' );
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$row = mysql_fetch_array($result);
$prodname = $row['prodname'];
$prodID = $row['prodID'];
if ($i % 5 == 0 || $i == 0) {
echo "<tr>";
}
echo "
<td>
<b>$prodname </b><br />
Product ID: $prodID<br />
<img src='/userpics/$prodID.jpg' height='200' width='200'>
</td>";
if ($i % 3 == 0 || $i == (mysql_num_rows($result)-1)) {
echo "</tr>";
}
}
?>
<table>
I am wating to show prodID, prodtitle and image all in the same "cell" but only have 3 columns (3 products per row).
How do i do this?
category
instead ofcatagory
. It won't fix your problem, but it will give you extra marks in your final class report (wink) – Fred -ii- Aug 2 '13 at 13:18SELECT *
andSELECT cola, colb, colc
? – Ollie Jones Aug 2 '13 at 13:20