sjones Posted March 21, 2006 Share Posted March 21, 2006 Hello, I am trying to select a category and then if it is a parent category, I would like to display with links all of the child categories with the vendors link that is in the child category. EXAMPLEChoose Category --> Submit --> (Query db to see if this is a parent category - if so echo)[b]Main Category->Sub Category 1[/b]-->Vendor 1 (link)-->Vendor 2 (link)[b]->Sub Category 2[/b]-->Vendor 1 (link)[b]->Sub Category 3[/b]-->Vendor 1 (link)-->Vendor 2 (link)If the category choosen was not a parent category then display vendors in that category EXAMPLE[b]Main Category [/b] (is not a parent category) -->Vendor 1 (link)-->Vendor 2 (link)The two tables in the DB that are controling this are[b]Categories[/b]cat_idparent_idcat_name[b]Vendors[/b]vendor_idvendor_namecat_idfile_nameactive_idI know this is probably a simple solution, but I have tried for about 5 days to code this. Can someone please help.Here is the code: just one of the hundreds that I have tried.<?phpsession_start();include ('../connections/mysql_connect.php');if (!isset($_POST['submit'])) { echo "<span class='content_blank'><strong>Please choose a category...</strong></span><BR><BR>"; echo "<form method='POST' action='cat_nav.php'> <select name='cat_id'> <option>- Please select one -</option>\n"; $qry = mysql_query("SELECT * FROM categories WHERE parent_id = 0;"); while($rows = mysql_fetch_assoc($qry)) { echo "<option value='".$rows['cat_id']."'>".$rows['cat_name']."</option>\n"; } echo "</select> <input name='submit' type='submit' value='View'> </form>";}?> Link to comment https://forums.phpfreaks.com/topic/5423-category-display/ Share on other sites More sharing options...
trq Posted March 21, 2006 Share Posted March 21, 2006 Though fairly complex, I usually use nested sets to organize data into a hierarchy. Maybe [a href=\"http://www.phpriot.com/d/articles/php/application-design/nested-trees-1/index.html\" target=\"_blank\"]this[/a] article will help you. Link to comment https://forums.phpfreaks.com/topic/5423-category-display/#findComment-19356 Share on other sites More sharing options...
sjones Posted March 21, 2006 Author Share Posted March 21, 2006 Thanks for the info, I read that article and that is way to complex for me right now.That will be a project for down the road. Link to comment https://forums.phpfreaks.com/topic/5423-category-display/#findComment-19361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.