Scorpion28 Posted August 1, 2012 Share Posted August 1, 2012 I'm using a php form, with all selections for a profile based site, the selections are store in a mysql db. How can I bring the selections back out of the db and show them in a new update profile form for the users profile? <div id="profile_info"> <form> <div id="profile_info_item"> <label> <select name="r_status" id="r_status"> <option value="0" selected="selected">Single</option> <option value="1">Married</option> <option value="3">Seperated</option> <option value="2">Divorced</option> <option value="4">Widowed</option> <option value="5">Tell You Later</option> </select> </label> </div> <div id="profile_info_item"> <select name="race" id="race"> <option value="0">Caucaisan</option> <option value="1">Black</option> <option value="2">Hispanic</option> <option value="3">Asain</option> <option value="4">Indian</option> <option value="5">European</option> <option value="6">Middle Eastern</option> <option value="7">Mixed Black / White</option> <option value="8">Native American</option> <option value="9">Other Ethnicity</option> </select> </div> <div id="profile_info_item"> <select name="age" id="age"> <option value="0" selected="selected">18-21</option> <option value="1">21-23</option> <option value="2">23-25</option> <option value="3">25-27</option> <option value="4">27-29</option> <option value="5">29-31</option> <option value="6">31-33</option> <option value="7">33-35</option> <option value="8">35-37</option> <option value="9">37-39</option> <option value="10">39-41</option> <option value="11">41-43</option> <option value="12">43-45</option> <option value="13">45-47</option> <option value="14">47-49</option> <option value="15">49-51</option> <option value="16">51-53</option> <option value="17">53-55</option> <option value="18">55-57</option> <option value="19">57-59</option> <option value="20">59-61</option> <option value="21">61-63</option> <option value="22">63-65</option> <option value="23">65-67</option> <option value="24">67-69</option> <option value="25">69-71</option> <option value="26">71-73</option> <option value="27">73-75</option> <option value="28">75-77</option> <option value="29">77-79</option> <option value="30">79-81</option> <option value="31">81-83</option> <option value="32">83-85</option> <option value="33">85-87</option> <option value="34">87-89</option> <option value="35">89-91</option> <option value="36">91-93</option> <option value="37">93-95</option> <option value="38">95-97</option> <option value="39">97-99</option> <option value="40">99-101</option> <option value="41">101-103</option> </select> </div> <div id="profile_info_item"> <select name="orie" id="orie"> <option value="0">Straight</option> <option value="1">Bi-Curious</option> <option value="2">Bi-Sexual</option> <option value="3">Gay</option> <option value="4">Lesbian</option> </select> </div> <div id="profile_info_item"> <select name="orie" id="orie"> <option value="1">Male</option> <option value="2">Female</option> <option value="3">TS/TG/TV</option> </select> </div> <div id="profile_info_item"> <select name="body" id="body"> <option value="0">Thin</option> <option value="1">Athletic</option> <option value="2">Average</option> <option value="3">BBW</option> <option value="4">A Few Extra Pounds</option> <option value="5">Muscular</option> <option value="6">Curvy</option> <option value="7">Show You Later</option> </select> </div> <div id="profile_info_item"> <select name="height" id="height"> <option value="0">less than 5ft</option> <option value="1">5ft 1in</option> <option value="2">5ft 2in</option> <option value="3">5ft 3in</option> <option value="4">5ft 4in</option> <option value="5">5ft 5in</option> <option value="6">5ft 6in</option> <option value="7">5ft 7in</option> <option value="8">5ft 8in</option> <option value="9">5ft 9in</option> <option value="10">5ft 10in</option> <option value="11">5ft 11in</option> <option value="12">6ft</option> <option value="13">6ft 1in</option> <option value="14">6ft 2in</option> <option value="15">6ft 3in</option> <option value="16">6ft 4in</option> <option value="17">6ft 5in</option> <option value="18">6ft 6in</option> <option value="19">6ft 7in</option> <option value="20">6ft 8in</option> <option value="21">6ft 9in</option> <option value="22">6ft 10in</option> <option value="23">6ft 11in</option> <option value="24">7ft</option> <option value="25">7ft+</option> </select> </div> <div id="profile_info_item"> <select name="hair" id="hair"> <option value="0" selected="selected">Black</option> <option value="1">Brown</option> <option value="2">Blonde</option> <option value="3">Red</option> <option value="4">Gray</option> <option value="5">Bald</option> <option value="6">Mixture of Colors</option> </select> </div> <div id="profile_info_item"> <select name="eyes" id="eyes"> <option value="0">Brown</option> <option value="1">Blue</option> <option value="2">Green</option> <option value="3">Light Brown</option> <option value="4">Hazel</option> </select> </div> <div id="profile_info_item"> <input type="submit" name="submit" id="submit" value="Save Changes" /> </div> </form> </div> Quote Link to comment Share on other sites More sharing options...
jotorres1 Posted August 1, 2012 Share Posted August 1, 2012 Are all these selects done manually or dynamically? Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 1, 2012 Share Posted August 1, 2012 As jotorres1 was alluding to, you will want to create these select lists dynamically. You should have the values/text for the options stored in a database, array or something similar on the server-side. Then you can create a function/process to create the select lists AND auto-select a value based upon a preset. Here is an example: <?php function createSelectList($options, $selectedValue=false) { $output = ''; foreach($options as $value => $text) { $selected = ($value === $selectedValue) ? ' selected="selected"' : ''; $output .= "<option value=\"{$text}\"{$selected}>{$text}</option>\n" } return $output; } //Create arrays of all select lists/values. This can be retrieved from //database or with hard-coded arrays. If stored in arrays, put them in //a separate file and include them when needed $statuses = array( '0' => 'Single', '1' => 'Married', '2' => 'Seperated', '3' => 'Divorced', '4' => 'Widowed', '5' => 'Tell You Later', ); //Call function with the list of values to create the options $statusOptions = createSelectList($statuses, $selectedValueFromDB); //Then output the options in the HTML ?> <div id="profile_info"> <form> <div id="profile_info_item"> <label> <select name="r_status" id="r_status"> <?php echo $statusOptions; ?> </select> </label> </div> 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.