SpireLink Posted June 29, 2008 Share Posted June 29, 2008 HI. i am working on a program that have categories and sup categories, the thing that the main category have a prent_id=0 and the sup category hase a the parent category_id the probleme now that I wont to be able to update the parent_id and when the parent_id=0 it will show me an option says "no parent" with the value of 0 <SELECT SIZE='1' name='parent_id'>"; $categories = mysql_query("SELECT * FROM categories where category_id<>$category_id ",$db); while ($categories_data = mysql_fetch_array($categories)) { $category_id=$categories_data['category_id']; $category_title=$categories_data['category_title']; if($category_id == $parent_id) { echo"<OPTION SELECTED value='$category_id'>$category_title</option>"; } else { echo"<option value='$category_id'>$category_title</option>"; } } echo"</select> i have worked around it in the add section and am using this code <SELECT SIZE='1' NAME='parent_id' dir='rtl' tabindex='1'> <option value='0'>no parent</option>"; $categories = mysql_query("SELECT * FROM categories",$db); while ($categories_data = mysql_fetch_array($categories)) { $pcategory_id=$categories_data["category_id"]; $pcategory_title=$categories_data["category_title"]; echo"<option value='$pcategory_id'>$pcategory_title</option>"; } echo"</SELECT> Link to comment https://forums.phpfreaks.com/topic/112396-select-with-parent-and-child-categories/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.