apple 0 Report post Posted April 25, 2007 (edited) suppose i make a dropdown menu having value 1, 2, 3, 4, 5, one option can be selected, and selected option is stored in database.now i create an edit page, how do i display the selected value in the menu and other values in dropdown,for example,Menu is likeSelect One12345and i select 3, this 3 is stored in database, now on the edit page i want to show 3 as already selected,something like that.. [quote]<select name="select_thing"> <option value="1">1</option> <option value="2">2</option> <option value="3" selected>3</option> <option value="4">4</option> <option value="5">5</option></select>[/quote]I will be very thankful, if someone could help by explaining how do i make option 3 as selected.. eg. how i know option 3 is selected and stored in db. Edited April 21, 2012 by moderator (see edit history) Share this post Link to post Share on other sites
Saint_Michael 3 Report post Posted April 26, 2007 Here are some links to help you out.This is a wizard that designs a php drop down menuhttps://www.thesitewizard.com/wizards/navigationmenu.shtmlThis is a script that creates a dhtml drop down menuhttp://www.scriptdungeon.com/script.php?ScriptID=1010This site talks about what goes into a php drop down menu and provides files as wellhttp://www.phpclasses.org/package/1562-PHP-Generate-a-drop-down-menu-with-HTML-tables.htmlHopefully that helps give you an idea on what to look for in designing a php drop down menuGOOGLE KEYWORDS"drop down menu in php" Share this post Link to post Share on other sites
galexcd 0 Report post Posted May 12, 2007 Couldn't you just make an if statement? If you know how to get and set the values in the database already, all you'd have to do is somthing like: <select name="select_thing"><option value="1"<?phpif(mysql_result($result,"","value")==1) echo" selected";?>>1</option><option value="2"<?phpif(mysql_result($result,"","value")==2) echo" selected";?>>2</option><option value="3"<?phpif(mysql_result($result,"","value")==3) echo" selected";?>>3</option><option value="4"<?phpif(mysql_result($result,"","value")==4) echo" selected";?>>4</option><option value="5"<?phpif(mysql_result($result,"","value")==5) echo" selected";?>>5</option></select> If that's what you meant, here's a more code-conserving way of writing it:<?php ${mysql_result($result,"","value)}=" selected";?><select name="select_thing"><option value="1"<? echo $1 ?>>1</option><option value="2"<? echo $2 ?>>2</option><option value="3"<? echo $3 ?>>3</option><option value="4"<? echo $4 ?>>4</option><option value="5"<? echo $5 ?>>5</option></select> Share this post Link to post Share on other sites
hitmanblood 0 Report post Posted May 18, 2007 OK this solution will work also I encourage you to try it it looks more simple to me then others. I cannot tell is it because I use it and I am familiar with it or just because it is simpler then other. Good luck with whatever you are doingFor the script I think that it doesn't need any more explanation also I would like to point out that I took in count that when you have loaded this value from your database that then you have saved it in the initial_var that is initial variable. <select name="testlist"> <option <? if(initial_var == "1"){ echo 'selected'; } >? >1</option> <option <? else if(initial_var == "2"){ echo 'selected'; } >? >2</option> <option <? else if(initial_var == "3"){ echo 'selected'; } >? >3</option> <option <? else if(initial_var == "4"){ echo 'selected'; } >? >4</option> <option <? else{ echo 'selected'; } >? >5</option> </select> Share this post Link to post Share on other sites
iGuest 3 Report post Posted December 8, 2011 i have not fired a query from which i can get $result....do u have any other solution?plss help me out Share this post Link to post Share on other sites