jjmusicpro Posted May 27, 2008 Share Posted May 27, 2008 i was pulling a value from mysql, and i wanted to put that value into the drop down. the drop down has 3 values seattle, phoenix, and new york. the value from the drop down is always going to match one pulled from db.. so... if the value pulled from the db is say seattle, i wanted seattle to be selected in the drop down menu, but they can change it if they want, i just want it to be selected when they go to the page, with the values that match it form the db Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 27, 2008 Share Posted May 27, 2008 How about showing us the code you have? It'll be a simple case of adding selected="selected" to the relevant option through the use of an if statement, but if we knew the context we could help more. Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted May 27, 2008 Author Share Posted May 27, 2008 how do i make it so it wont write out that value again... so i pull "seattle" form the guys profile, and i make a form that i wanted to edit his info. so the form will have a select drop down box, with 3 values seattle, phoenix, and new york. instead of the drop down box starting off with phoenix or some other place, i wanted it to show the value selected as the one in the db. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 27, 2008 Share Posted May 27, 2008 yes like ginger said selected="selected" Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted May 27, 2008 Author Share Posted May 27, 2008 i tried setting an option value as you said but it didnt work <select name=\"payscale\"> <option selected=\"$payscale\"></option> <option value=\"seattle\">seattke</option> <option value=\"phoenix\">phoenix</option> <option value=\"new york\">new york</option> </select> Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted May 27, 2008 Author Share Posted May 27, 2008 anyone? ??? Quote Link to comment Share on other sites More sharing options...
Darklink Posted May 27, 2008 Share Posted May 27, 2008 No no. <select name=\"payscale\"> <option selected=\"selected\"></option> <option value=\"seattle\">seattke</option> <option value=\"phoenix\">phoenix</option> <option value=\"new york\">new york</option> </select> It must be selected="selected" Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted May 27, 2008 Author Share Posted May 27, 2008 i pull the variable from the db and it $selected = 'seattle" i tried to put your code below but it dosent work, it dosnt pull back info in selected list. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 27, 2008 Share Posted May 27, 2008 something like this: print "<select name='payscale'> <option value='' selected='selected'></option> while ($row = mysql_fetch_assoc($result){ $city = $row['city']; print "<option value='$city'>$city</option>\n"; } print "</select>"; Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 27, 2008 Share Posted May 27, 2008 can we see your latest code? Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted May 27, 2008 Author Share Posted May 27, 2008 my cities are hardcoded on the page, not in the database so i wanted the selected value to be the value retrieved in the db. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 28, 2008 Share Posted May 28, 2008 Try: <?php $cities = array('seattle','pheonix','new york');//array of cities //assuming $payscale is the variable containing the state name: echo '<select name="payscale">'; foreach($cities as $v){ $selected = ''; if($v == $payscale){ $selected = ' selected="selected" '; } echo '<option value="'.$v.'"'.$selected,'>'.$v.'</option>'; } echo '</select>'; ?> Quote Link to comment 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.