• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

problem with case select code

forcer

OSNN Senior Addict
#1
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?
 
#3
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
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'; 

}
    
?>
 

X-Istence

*
Political User
#5
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
Originally posted by X-Istence
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

:)
What's the point of that?
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,017
Latest member
bettyicrewsi