Rule #1: Pretty much anything is possible, if coded right.
Something like....(and i'm just pulling this off the top of my head so dont hold me to this being the best way to do it... and in fact i know it isnt because this isnt sanitized, but it's a demonstration)
PHP Code:
$res = mysql_query("SELECT * FROM categories");
while($row = mysql_fetch_array($res)) {
$cats[$row['categoryid']] = $row['categoryname'];
}
if(isset($_GET['category'])) {
$selcat = $_GET['category'];
}
if(isset($_GET['product'])) {
$prod_info = mysql_fetch_array(mysql_query("SELECT * FROM product WHERE productid = ".$_GET['product']));
//Prod_Info now gets stored for use in the main display.
$selcat = $prod_info['categoryid'];
}
if(isset($selcat)) {
echo "<a href='categorylist.php?category=".$selcat."'>".$cats[$selcat]."</a>";
unset($cats[$selcat]); //Gets rid of it for later.
$res = mysql_query("SELECT productid,name FROM products WHERE categoryid = ".$selcat);
while($row = mysql_fetch_array($res)) {
echo " <a href='product.php?product=".$row['productid']."'>".$row['name']."</a>";
}
}
foreach($cats AS $key => $cat) {
echo "<a href='categoryview.php?category=".$key."'>$".$cat."</a>";
}
Bookmarks