if i have a category page that im rendering by querying the subcategories in my database, then if i click on one of the subcategories it sends me to
mydomain.com/product_list.php?id=subcategory.
is there a way take the subcategory from the url to query the database to only show the products in that subcategory?
i think it’ll look something like:
$sql = mysql_query("SELECT * FROM products");
This can be obtained from
$_GETDOCs.So this would become:
Note I have cast the input variable to an integer to prevent SQL injection etc. As the ID must always be a number.
If you need to pass in a string then use
mysql_real_escape_string()DOCs on it first and don’t type cast to an integer(int):