Jump to content

Autoselecting a value in a dropdown menu


HaLo2FrEeEk

Recommended Posts

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.