Forum Moderators: coopster
Im trying to create a simple script that will "include" a differnt .php page, into another .php page based on the query string that is sent.
Im trying to acheive this so i can better organise my site that has several Sections, and Sub Sections.
For example:
[site.com...] - Includes/Requires the main section, (/pages/index_main.php).
[site.com...] - Includes/Requires the "About us" section, (/pages/index_about.php)
[site.com...] - Includes/Requires the "FAQ" section, (/pages/index_faqs.php)
[site.com...] - Includes/Requires the main Downloads section, (/pages/downloads_main.php).
[site.com...] - Includes/Requires the "screensaver downloads" section, (/pages/downloads_screensavers.php).
So far i achived this easily using a simple script, but... heres where the problem is...
[site.com...] - produces no require, so it doesnt include anything inside the main .php page (index.php for example) and the result is a messed up page layout with nothing in it.
Here's the code im using:
**START CODE**
<?
if ($go == 'about') { //if string = "about": load about subsection
require ('/home/jsnweb/public/html/pages/index_aboutus.php');
}
if ($go == 'faq') { //if string = "faq" load faqs subsection
require ('/home/jsnweb/public/html/pages/index_faqs.php');
}
else if ($go == '') { //if string = "BLANK" load MAIN section
require ('/home/jsnweb/public/html/pages/index_main.php');
}
?>
**END CODE**
So as you can see, i either need a way to tell it if the string equals anything other than "about","faq", etc it inserts the main section into the page....
.. or ...
Perhaps another way, even a better way of doing this and acheveing the same simple result?
Any help would be much appreciated, Thanks. =)
Instead of
else if ($go == '') { //if string = "BLANK" load MAIN section
require ('/home/jsnweb/public/html/pages/index_main.php');
}
how about:
else { //if string = "BLANK" or anything else load MAIN section
require ('/home/jsnweb/public/html/pages/index_main.php');
}
Shawn
<edit> Oh, I see I am too late </edit>
"...Adding "else" instead of "else if ('do something'); doesnt quite work, it loads both pages if the correct string is passed..."
Yes it does. You probably made an error when you edited... You probably added a semicolon somewhere after the 'else', and before the 'require', so it is going: else {do nothing};, and the require is outside the else construct.
But I see that you have solved it using the 'case' construct, so well done for getting it going!
Shawn