Display my database via PHP - Can you help?

I have a database and want to display it's content in this manner:

[Prod 1] [Prod 2] [Prod 3] [Prod 4]

[Prod 5] [Prod 6] [Prod 7] [Prod 8]

Just 8 results per page is all I need.
Here is what my code is like at the moment.

<?
include 'database_conn.php'; // make db connection

$sql = "SELECT title, category, description, price, postage FROM rugs";

$queryresult = mysql_query($sql) or die (mysql_error());

while ($row = mysql_fetch_array($queryresult)) {

$title = $row['title'];
$category = $row['category'];
$description = $row['description'];
$price = $row['price'];
$postage = $row['postage'];

echo "<th>Title: $title<br />";
echo "Category: $category<br />";
echo "Description: $description<br />";
echo "Price: $price<br />";
echo "Postage: $postage";
}

mysql_free_result($queryresult);
mysql_close($conn);
?>
 
try this:

$query="SELECT * FROM rugs ";

$result=mysql_query($query)or die("query rugs error");

$num=mysql_numrows($result);

$j=0
while ($j < $num) {

$title=mysql_result($result, $j ,"title"); //the "title" in the brackets is the name of the column in the sql database. same for all of these below
$category=mysql_result($result, $j ,"category");
$description=mysql_result($result, $j ,"description");
$price=mysql_result($result, $j ,"price");
$postage=mysql_result($result, $j ,"postage");

//then you can do:

echo "<th>Title: $title
";
echo "Category: $category
";
echo "Description: $description
";
echo "Price: $price
";
echo "Postage: $postage";
}

//or what ever you want to display

j++;//when incremented it will go to the next row
}//end while

hope this helps
 
Back
Top