0

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

2
Contributors
3
Replies
5
Views
12 Years
Discussion Span
Last Post by zippee
0

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.

0

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

0
$cat = $_GET['cat'];
if(empty($cat)) {
  $query = "SELECT * FROM table_category";
} else {
  $query = "SELECT * FROM table_category WHERE cat = '$cat' ";
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.