ciber Posted May 17, 2010 Share Posted May 17, 2010 OK hopefully this makes sense I have a mysql table, which has an id, an a category name. My product table has its information, and a category id. Now my problem, when I am editing a product, I want the category to be selected. How do I get php to echo all the items in the category, but get it to also add the selected attribute to the item which is selected in the products database Thanks Link to comment https://forums.phpfreaks.com/topic/202079-confusing-layout-for-a-selection-list-help/ Share on other sites More sharing options...
scampbell Posted May 17, 2010 Share Posted May 17, 2010 Make a function to display it and pass the variable to it. Here is one I wrote to select formats for an old project function formats($val=""){ echo "<select name='formats' class='vshort'>\n<option value='0' rel='none'>Format</option>\n"; $c_q = @debug_mysql_query("SELECT format_id, format_name, format_rel FROM album_format"); while($c = mysql_fetch_array($c_q)){ $cid = $c["format_id"]; $name = htmlize($c["format_name"]); $selected = ($cid == $val)?"selected":""; echo "<option $selected value='$cid' rel='" . $c[format_rel] . "'>$name</option>\n";} echo "</select>"; } Theres some functions in there you will need to change but hopefully it gives you an idea. Link to comment https://forums.phpfreaks.com/topic/202079-confusing-layout-for-a-selection-list-help/#findComment-1059683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.