SysAdm Posted November 4, 2008 Share Posted November 4, 2008 Have a database with all 50 states in one column and another column that has 0 or 1 depending on if state is active. Anyways, I have the code to generate the drop down menu with all the 50 states... works perfectly... now, when a user selects a state and hits SEARCH, I want their selection to stay selected, not default back to CHOOSE STATE.... Right now with this code, each entry in the Drop Down is SELECTED not just the one that is chosen.... function getStates($stateid) { global $state_tbl; $allstates = q("select * from $state_tbl where state_is_valid=0 order by state_name"); while ($statenames = mysql_fetch_array($allstates)) { $string.="<option value='$statenames[state_name]'"; if (is_array($stateid)) { if (in_array($statenames[state_name],$stateid)) $string.=" selected"; } elseif ($stateid==$statenames[state_name]) $string.=" selected"; $lStateName = $statenames[state_name]; $string.=">$lStateName"; $string.="</option>"; } return $string; } Basically all I'm doing is trying to dynamically pull my data in a Drop Down and have it REMEMBER what the user selects what the page refreshes with a SEARCH. Any help would be greatly appreciated and thanks in advance... SysAdm Quote Link to comment Share on other sites More sharing options...
priti Posted November 4, 2008 Share Posted November 4, 2008 Hi, Register the selected value in $_SESSION while creating select dynamically simple add if($statenames[state_name] == $_STESSION['state']) { $string.="<option value='$statenames[state_name]' "selected">"; }else { $string.="<option value='$statenames[state_name]'>"; } Thanks 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.