I know almot nothing about PHP but I am making a stab at this. I have a PHP/MySQL script than I am editing and integrating into a site. I have done a decent job so far or formatting the output. However, I have come to a point where I need to estblish/call a variable from the SQL database to make the format look right and I do not know what to do. The script is an inventory script. DB consists of products that have ID, category, description etc. To display all products in catagory I have (index.php?cat=2) this shows all product in category 2 etc. I wanted some variable html based on category and did the following which works. <? if (($cat >= 1) && ($cat <= 13)) { include("../menus/menu1.php"); }else if (($cat >= 21) && ($cat <= 23)) { include("../menus/menu2.php"); }else if (($cat >= 15) && ($cat <= 17)) { include("../menus/menu3.php"); }else if (($cat >= 18) && ($cat <= 20)) { include("../menus/menu4.php"); }else if ($cat == 24) { include("../menus/menu5.php"); } ?> The problem comes in that I also have a product.php to display the actually product. It uses (product.php?id=3) to display product 3 etc. I want to display the same variable html base on the category but the $cat variable does not get established on the product.php page. I need to know what code I can use to establish the $cat variable based on the product id on the product.php page. The current PHP code on the product page is: mysql_query("UPDATE product SET viewed=viewed+1 WHERE id=$id"); $qr1 = mysql_query("SELECT * FROM product WHERE id=$id"); $prod = mysql_fetch_object($qr1); Thanks in advance for any assistance.
Each product belongs in a category so the product table certainly has the necessary category ID stored in it. Your job is to extract that field from the table and use it as the $cat variable. Right here, the code loads in the product data: $qr1 = mysql_query("SELECT * FROM product WHERE id=$id"); $prod = mysql_fetch_object($qr1); So now you have an array named $prod that contains all of the data about that product. Inside of that array there will be a category id. It could be called $prod['cat'] or $prod['category'] or $prod['categoryid'] or $prod['catid'] depending on the developer's adherence to naming conventions. Once you find out what that is called, you can set the $cat variable to equal the same thing... essentially finding out what category the product is in. $cat = $prod['categoryid'];
Thanks Hoff. That actually did not work but It got me thinking in the right direction. I used this: $cat = stripslashes($prod->cat); and it worked.