son.of.the.morning Posted December 21, 2011 Share Posted December 21, 2011 I need my select dropdown to show the relevant option. I am using a GET action to pass the id of an article to another page (edit article page) with this i am selecting that specific record and passing it's data into form object in order to be modified and updated. The only issue is my category list is a dropdown and i need it to display the relivent category for that specific record. hope that makes sence Quote Link to comment https://forums.phpfreaks.com/topic/253599-a-diffrent-selected-value-of-a-select-form-depending-on-a-var/ Share on other sites More sharing options...
litebearer Posted December 21, 2011 Share Posted December 21, 2011 please post the relevant code that you have thus far Quote Link to comment https://forums.phpfreaks.com/topic/253599-a-diffrent-selected-value-of-a-select-form-depending-on-a-var/#findComment-1300050 Share on other sites More sharing options...
son.of.the.morning Posted December 21, 2011 Author Share Posted December 21, 2011 <?php if(isset($_GET['id'])) { $id = $_GET['id']; $a = "SELECT * FROM blog_posts WHERE id = $id"; $query = mysql_query($a) or die (mysql_error()); $return = mysql_fetch_array($query); } else { } ?> <select name="color" class="SelectColor"> <option id="red" value="red">red</option> <option id="blue" value="blue">blue</option> <option id="green" value="green">green</option> <option id="grey" value="grey">grey</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/253599-a-diffrent-selected-value-of-a-select-form-depending-on-a-var/#findComment-1300052 Share on other sites More sharing options...
litebearer Posted December 21, 2011 Share Posted December 21, 2011 Untested, unproof-read; however... <?PHP $colors = array("red","blue","green","grey"); $color_count = count($colors); $what_color = "blue"; /* use the color from wherever to set this variable */ ?> <select name="color" class="SelectColor"> <?PHP for($i=0;$i<$color_count;$i++) { ?> <option id="<?PHP echo $colors[$i]; ?>" value="<?PHP echo $colors[$i]; if($what_color == $colors[$i]) { echo "SELECTED"; } ?>"> <?PHP echo $colors[$i]; ?> </option> <?PHP } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/253599-a-diffrent-selected-value-of-a-select-form-depending-on-a-var/#findComment-1300099 Share on other sites More sharing options...
son.of.the.morning Posted December 22, 2011 Author Share Posted December 22, 2011 Thats for the help. I created a really simple solution. Quote Link to comment https://forums.phpfreaks.com/topic/253599-a-diffrent-selected-value-of-a-select-form-depending-on-a-var/#findComment-1300429 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.