michaelk46 Posted October 16, 2009 Share Posted October 16, 2009 Hey all, I am still fairly new to PHP programming and I am trying to put together a page where you select search terms from a drop down menu and it keeps the menu at your search choice in the menu after the search. Here is the code I was suggested to use, but I am having problems understanding how it keeps the choice in the menu. I can almost understand how it works, but I need a little push to grasp it. Here is the code: foreach($options as $key => $content) { if ($key == $value) $select = ' selected="selected"'; else $select = NULL; $html .= '<option value="' . htmlspecialchars($key) . '"' . $select . '>' . htmlspecialchars($content) . '</option>' . "\n"; } Now I understand how to walk through the code, but I am having trouble understanding how it holds over the choice. THanks in advance for the help... Quote Link to comment https://forums.phpfreaks.com/topic/177919-solved-explanation-help/ Share on other sites More sharing options...
cags Posted October 16, 2009 Share Posted October 16, 2009 It simply loops through the contents of the options array echo'ing them out. If the current item in the array matches $value (which must have been set further up the code using something like $value = $_POST['name_of_select_node']) it includes selected="selected" as part of the node. In HTML this basically means select this item in the list. Quote Link to comment https://forums.phpfreaks.com/topic/177919-solved-explanation-help/#findComment-938084 Share on other sites More sharing options...
michaelk46 Posted October 17, 2009 Author Share Posted October 17, 2009 Sorry to take so long to respond... I had another PHP server problem to troubleshoot. THis helped out a lot Thank You for your explanation Quote Link to comment https://forums.phpfreaks.com/topic/177919-solved-explanation-help/#findComment-938662 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.