problem with case select code

Discussion in 'Web Design & Coding' started by forcer, Oct 8, 2003.

  1. forcer

    forcer OSNN Senior Addict

    Messages:
    413
    PHP:
    <?php  
    if (!$page) { 
        include 
    'home.php'
    } elseif (
    file_exists($page.".php")) { 
        switch (
    $page) {  
            case 
    'home':  
            include 
    'home.php'; break;
            case 
    'about':
            include 
    'about.php'; break;
            case 
    'profiles':
            include 
    'profiles.php'; break;
            case 
    'audio':
            include 
    'audio.php'; break;
            case 
    'photos':
            include 
    'photos.php'; break;
            case 
    'videos':
            include 
    'videos.php'; break;
            case 
    'choons':
            include 
    'choons.php'; break;
            case 
    'guestbook':
            include 
    'guestbook.php'; break;
            case 
    'links':
            include 
    'links.php'; break;
            case 
    'xtra':
            include 
    'xtra.php'; break;
            case 
    'contact':
            include 
    'contact.php'; break;
        default:  
        include 
    '404.php'
        } 
        } else { 
        include 
    '404.php'
        }
        
        switch (
    $u) {
            case 
    'reflex':  
            include 
    'profiles/reflex.php';  break;
            case 
    'scottyg'
                                    include 
    'profiles/scottyg.php'; break;
        }
    ?>
    this is the code i use for my case select... only problem is if i go to the page...
    index.php?page=profiles&u=scottyg

    it will display profiles page and the scottyg page... but i just want it to display the scotty g page...

    how can i fix this?
     
  2. Take out the profiles& line in the code?
    I dont know enough to about php to give you a direct answer :/
     
  3. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    Insert the switch($u) into switch($page) like this:
    Code:
    <?php
     switch ($page) {  
            case 'bla1':  
            include 'home.php'; break;
            switch($u){
                   case 'something':
                   DoSomething();
                   break;
            }
            default:
             print "booboo";
    }
    
    But that would be difficult as you have a lot of cases. But, I think I can remove those cases, just give me a minute, then I shall try something.
     
  4. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    This might work:
    PHP:
    <?php  
    if (!$page) { 
     include 
    'home.php'

    //Does the file exist?
    } elseif (file_exists($page.".php")) { 
      
    //include file with the name of whatever ?page=bert is
      
    include '$page.php';
     
      
    //Does the file ($u) exist?
      
    if (file_exists("profiles/".$u.".php"){
        
    //include file with the name of whatever &u=ernie is
        
    include 'profiles/$page.php';
      }else{
        print 
    "I am sorry, but that user does not exist";
      }

    }else{ 
     include 
    '404.php'

    }
        
    ?>
     
  5. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    To your first case statement, add another one that called empty, and then instead of your URL being:

    index.php?page=profiles&u=scottyg, make it
    index.php?page=empty&u=scottyg

    :)
     
  6. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    What's the point of that?