hello

i have decided to split my products into categories.

each product has a category from 1-5.

how do i make this page display products relevant to the category
I have made links to each category on this page on the left. I dont know if this is the way the link should look or what code i need to put into products.php

http://www.bluetipdvd.co.uk/products.php

the row in the mysql table is called 'cat'
thanks

simon

Create link with data tail behind. for example: www.yoursite.com/products.php?cat=1
The PHP script in the category page can then use this data to query database.

$cat = $_GET['cat'];
$query = "SELECT * FROM table_category WHERE cat = '$cat' ";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
	$product_id  = $row['product_id'];
	$product_name  = $row['product_name'];
	// more data from this product to follow
} // looping to get other products under the same category
mysql_free_result($result);

Hope this help.

hi thanks for that its worked great

just wondering what you need to do now so that product.php page with out the added bit on the end will show all products.

will be checking out your site while i await your response

thanks

sy

$cat = $_GET['cat'];
if(empty($cat)) {
  $query = "SELECT * FROM table_category";
} else {
  $query = "SELECT * FROM table_category WHERE cat = '$cat' ";
}
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.