HaLo2FrEeEk Posted August 24, 2007 Share Posted August 24, 2007 I'm revamping my sites administration panel and I put in a dropdown menu to select the section to administrate (it was a LOT better than the list of links I had before, I'll probably update it some more though) and I want to know how I can autoselect whatever page I'm on in the dropdown menu, for example, here's the menu: Administrate: News Roster Update Roster Update Emblems Click Counter Pending Affiliates If I select Update Roster, I want it to automatically have Update Roster selected when I load that page. Basically I've got the indx.php which has a large switch statement that handles all the different actions that can be taken, the switch statement uses include to call up the corresponding file, which also has a switch statement to handle all the different functions of that particular section. Roster has Update and Update Emblems, and Add a new member; Click Counter has Add a new link, delete link, reset to zero, etc. I want the page I'm on to be the selection in the dropdown menu. How can I use php to do this? Quote Link to comment https://forums.phpfreaks.com/topic/66468-autoselecting-a-value-in-a-dropdown-menu/ Share on other sites More sharing options...
GingerRobot Posted August 24, 2007 Share Posted August 24, 2007 Well, if its all going through index.php and you pass an action to it through the URL, then it would be something like: <?php $action = $_GET['action']; $pages = array('news','roster');//fill the array with all of your pages echo '<select name="page">'; foreach($pages as $v){ echo "<option value='$v'"; echo $action==$v? "selected='selected'": ""; echo ">$v</option>"; } echo '</select>'; ?> Makes it much easier by putting all the possible pages in an array. Quote Link to comment https://forums.phpfreaks.com/topic/66468-autoselecting-a-value-in-a-dropdown-menu/#findComment-332910 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 29, 2007 Author Share Posted August 29, 2007 So that means that if I update and add functionality to the admin index page, then I have to update the array too. This is way complicated. Is there any way to make it so I don't have to have all the values in 3 different places? For example: index.php: switch ($action) { case "news": include('./news.php'); break; case "news_insert": include('./news.php'); break; etc... news.php: switch ($_REQUEST['action']) { case "news_insert": // Code to insert from the form below break; default: // Form to submit news break; etc... Array in index.php: $c = array('news', 'news_insert', etc...); There's a lot to go wrong there, any way I can make it a better system? Quote Link to comment https://forums.phpfreaks.com/topic/66468-autoselecting-a-value-in-a-dropdown-menu/#findComment-336905 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 29, 2007 Author Share Posted August 29, 2007 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/66468-autoselecting-a-value-in-a-dropdown-menu/#findComment-337026 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.