scmeeker Posted July 18, 2010 Share Posted July 18, 2010 I would like add subcategories to my main categories. For example: Paintings (would be a main category) oil (sub-category) acrylic (sub-category) watercolor (sub-category) When a user first comes to the webpage, it would list all the main categories. Then, when the user clicks on a main category, the Sub-categories dynamically drop down, pushing down the other main categories (but still being able to view them). I already have a separate sub-category table ready to pull from that match up with the corresponding category. This code, pulls from the category table and lists the main categories along the side and when clicked brings up all matching products according to the category. But now I would like to take it one more step and have the sub-category list drop down under the main category while still bringing up the products under that category. Then a user could choose to sort even further through the products by choosing the sub-category. Hopefully I'm making some sense here. Thanks for your help. //Set the selected category $selected_cat = (isset($_GET["cat_id"])) ? $_GET["cat_id"] : false; //show categories first $result = mysql_query("SELECT cat_id, cat_title FROM category ORDER BY cat_id") or die(mysql_error()); if (mysql_num_rows($result) < 1) { $categoryList = "<p><em>Sorry, no categories to browse.</em></p>"; } else { //Display the categories while ($cats = mysql_fetch_array($result)) { $categoryList .= "<a href=\"listtest5.php?cat_id={$cats['cat_id']}\">{$cats['cat_title']} <br /></a>\n"; if ($cats['cat_id']==$selected_cat) { //get items $get_items_sql = mysql_query("SELECT id, image_upload_box, username, title, price, date FROM product WHERE cat_id = '{$selected_cat}' ORDER BY date $pages->limit") or die(mysql_error());; if (mysql_num_rows($get_items_sql) < 1) { $content = "<p><em>Sorry, no items in this category.</em></p>\n"; } else { $content .= "<ul>\n"; while ($items = mysql_fetch_array($get_items_sql)) { $item_url = "items3.php?id={$items['id']}=username={$items['username']}"; $item_title = stripslashes($items['title']); $item_price = $items['price']; $item_photo = $items['photo']; $item_username = $items['username']; $item_date = $items['date']; $content .= ""; Quote Link to comment https://forums.phpfreaks.com/topic/208072-adding-a-subcategory/ Share on other sites More sharing options...
Stalingrad Posted July 19, 2010 Share Posted July 19, 2010 I think you would use JavaScript in this case. I'm not really good with JavaScript. Try Googling... "JavaScript Dropdown Menu". Sorry I couldn't help you much. ='^[ Quote Link to comment https://forums.phpfreaks.com/topic/208072-adding-a-subcategory/#findComment-1088372 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.