Jump to content

Linda A

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Linda A's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. In addition to the error mentioned in the previous post, I've also found another problem. When I try this code out on an actual page (the page with it on is then included into the page at the top), the page doesn't load beyond the include code. Is that due to the 'die' killing the rest of the page too? If so, how I can get to just stop processing the script in question, but to go on to process the rest of the page?
  2. $WhichMainMenuItem is an array defined at the beginning of the script. I didn't include the whole before because it got so spammy, but here it is: [code] <?php $WhichMainMenuItem = Array ( '/FAQ/' => 'VolumeI', '/SSM/' => 'VolumeI', '/Concordance/' => 'VolumeII', '/Encyclopaedia/' => 'VolumeII', '/Heraldry/' => 'VolumeII', '/History/' => 'VolumeII', '/Characters/' => 'VolumeIII', '/Prophecies/' => 'VolumeIII', '/Artwork/' => 'VolumeIV', '/Books/' => 'VolumeIV', '/Images/' => 'VolumeIV' ); $WhichMainMenuItemID = Array ( '/FAQ/' => 'main01', '/SSM/' => 'main01', '/Concordance/' => 'main02', '/Encyclopaedia/' => 'main02', '/Heraldry/' => 'main02', '/History/' => 'main02', '/Characters/' => 'main03', '/Prophecies/' => 'main03', '/Artwork/' => 'main04', '/Books/' => 'main04', '/Images/' => 'main04' ); $WhichSubMenu = $WhichMainMenuItem; $WhichSubMenuItem = Array ( '/FAQ/' => 'FAQ', '/SSM/' => 'SSM', '/Concordance/' => 'Concordance', '/Encyclopaedia/' => 'Encyclopaedia', '/Heraldry/' => 'Heraldry', '/History/' => 'History', '/Characters/' => 'Characters', '/Prophecies/' => 'Prophecies', '/Artwork/' => 'Artwork', '/Books/' => 'Books', '/Images/' => 'Images' ); $URL = $_SERVER['PHP_SELF']; $Parts = explode("/",$URL); if ($Parts[2] != "index.php" && $Parts[2] != "index.html") { $CurrentSection = "/".$Parts[2]."/"; } elseif ($Parts[2] == "index.html") { die; } elseif ($Parts[2] == "index.php" && $Parts[3] != "NULL" && array_key_exists($WhichMainMenuItem,$Parts[3])) { $CurrentSection = "/".$Parts[3]."/"; } else { die; } if(isset($CurrentSection)){ $MainMenuItem = $WhichMainMenuItem[$CurrentSection]; $MainMenuItemID = $WhichMainMenuItemID[$CurrentSection]; $SubMenu = $WhichSubMenu[$CurrentSection]; $SubMenuItem = $WhichSubMenuItem[$CurrentSection]; }; ?> [/code] Do I have the correct syntax then for checking whether $Parts[3] is part of this array? Edited to add: I tried out the modified code, and I now get this error: Warning: array_key_exists(): The second argument should be either an array or an object in <filename>. However, it only occurs when I access the code on an URL including the 'www'. So, wwww.domain.com/Citadel/About/ generates the error, but not domain.com/Citadel/About/. Why would that happen?
  3. Hi, I am using a php array as part of a menu, to determine which section is currently being viewed and based on that serve up the correct submenu. I don't really know much about php myself, so I had help putting the code together, and now I have run into a few instances where the code fails. To fix this, I need to add some further conditions to the array, so I cobbled together an example of what I'd like it to do: [code] $URL = $_SERVER['PHP_SELF']; $Parts = explode("/",$URL); Step 1: If $Parts[2] is NOT index.php or index.html, go ahead and define $CurrentSection. Not sure how I would get it to not to go onto step 2 and 3 if step 1 is as it should be, though. if ($Parts[2] != "index.php|index.html") {   $CurrentSection = "/".$Parts[2]."/"; } Step 2: If step 1 wasn't true, check to see if $Parts[2] IS index.html. If so, terminate (the default menu should be displayed, so no values need to be set). Again, if this is true, it shouldn't go on to step 3. elseif ($Parts[2] == "index.html") {   die; } Step 3: If part 2 is index.php and $Parts[3] exists and $Parts[3]  is within the array, set $CurrentSection. Otherwise, terminate. elseif ($Parts[2] == "index.php") && ($Parts[3] != "NULL") && (array_key_exists($WhichMainMenuItem,$Parts[3])) {   $CurrentSection = "/".$Parts[3]."/"; } else {   die; } Step 4: The following variables should only be defined in those instances when $CurrentSection has been defined. $MainMenuItem = $WhichMainMenuItem[$CurrentSection]; $MainMenuItemID = $WhichMainMenuItemID[$CurrentSection]; $SubMenu = $WhichSubMenu[$CurrentSection]; $SubMenuItem = $WhichSubMenuItem[$CurrentSection]; [/code] If anyone could help me to get this to work as intended, I would really appreciate it. :)
×
×
  • 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.