marccesar Posted June 9, 2006 Share Posted June 9, 2006 i have a drop down menu which is being built from values in my database..how do i specify which value to select when the page loads? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/11593-dropdown-menu-question/ Share on other sites More sharing options...
poirot Posted June 9, 2006 Share Posted June 9, 2006 You can use Javascript and select it when the page loads.... Or figure out which value you want to replace to select and use str_replace, preg_replace and so on.Like:[code]$pattern = 'value="' . $should_be_selected . '"';str_replace($pattern, $pattern . ' selected="selected"', $subject);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11593-dropdown-menu-question/#findComment-43739 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 I think I've already answered this in another thread, but I can't remember if you posted it or not. Either way:[code]$sql = mysql_query("SELECT *FROM `table`WHERE `something`='1'"); // Do the database queryecho "<select name=\"members\">"; // Start off the drop-down menuwhile($row = mysql_fetch_array($sql)){echo "<option";if($row['name'] == 'fyorl'){echo " selected>"; // This makes the option selected}else{echo ">";}echo "$row[name]</option>";}echo "</select>"; // End the menu[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11593-dropdown-menu-question/#findComment-43740 Share on other sites More sharing options...
marccesar Posted June 9, 2006 Author Share Posted June 9, 2006 thanks for your help, worked perfectly! Quote Link to comment https://forums.phpfreaks.com/topic/11593-dropdown-menu-question/#findComment-43762 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.