josephbupe Posted April 2, 2013 Share Posted April 2, 2013 Hi, How can I use the select option box to display an option value saved to a table and use the same select box to also select any other value If I want to change the saved value? Link to comment https://forums.phpfreaks.com/topic/276416-select-option-box-to-display-data-from-table/ Share on other sites More sharing options...
abrahamgarcia27 Posted April 2, 2013 Share Posted April 2, 2013 Check this sample <p> <label>State</label> <span class="formwrapper"> <select data-placeholder="Choose a State..." name="state" class="chzn-select" tabindex="2"> <?php $state_list = array('AL'=>"Alabama", 'AK'=>"Alaska", 'AZ'=>"Arizona", 'AR'=>"Arkansas", 'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware", 'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii", 'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas", 'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts", 'MI'=>"Michigan", 'MN'=>"Minnesota", 'MS'=>"Mississippi", 'MO'=>"Missouri", 'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon", 'PA'=>"Pennsylvania", 'RI'=>"Rhode Island", 'SC'=>"South Carolina", 'SD'=>"South Dakota", 'TN'=>"Tennessee", 'TX'=>"Texas", 'UT'=>"Utah", 'VT'=>"Vermont", 'VA'=>"Virginia", 'WA'=>"Washington", 'WV'=>"West Virginia", 'WI'=>"Wisconsin", 'WY'=>"Wyoming"); foreach ($state_list as $key => $value) { ?> <option value="<?php echo $key; ?>" <?php if($record['state'] == $key)echo "selected";?>><? echo $value; ?></option> <?php } ?> </select> </span> </p> Link to comment https://forums.phpfreaks.com/topic/276416-select-option-box-to-display-data-from-table/#findComment-1422412 Share on other sites More sharing options...
josephbupe Posted April 2, 2013 Author Share Posted April 2, 2013 I will try that. Thanx. Link to comment https://forums.phpfreaks.com/topic/276416-select-option-box-to-display-data-from-table/#findComment-1422418 Share on other sites More sharing options...
josephbupe Posted April 2, 2013 Author Share Posted April 2, 2013 Hi, I meant for categories in another table, unlike in your case where the list is hard coded. Link to comment https://forums.phpfreaks.com/topic/276416-select-option-box-to-display-data-from-table/#findComment-1422439 Share on other sites More sharing options...
DaveyK Posted April 2, 2013 Share Posted April 2, 2013 so you fill the array with the content from a table using SQL Link to comment https://forums.phpfreaks.com/topic/276416-select-option-box-to-display-data-from-table/#findComment-1422441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.