Hi, Guys! I need some help programming some small piece of PHP code. I have a file index.php In there i want to show 1 type of content if users go directly to index.php. If they go to: index.php?id=index2 Than i would like to replace the current content and show the content for "index2" f.eks <if index2> content here </close if> <if index3> content here </close if> Could anyone help me with this?? Thanks!
hey dude try this // check for _GET['page'] -> index.php?page= ... if (isset($_GET['page'])) { $page = trim($_GET['page']); // delete whitespace // check what is requested switch($page) { case 'home': // if index.php?page=home then include('home.php'); break; // jump out of switch() case 'about': // if index.php?page=about then ... include('about.php'); break; default: // if something like index.php?page=blabla then include('home.php'); break; } } PHP:
Hello Neo_The_One, Instead of using multiple IF statements use Switch statement. Example: <?php $id = $_GET['id']; // Switch ID statement switch ($id) { case "index2": echo "content here"; break; // jump out of switch() case "index3": echo "content here"; break; // jump out of switch() default: // default action if no argument is passed or no match. echo "content here"; break; } ?> Now you can also use 2 types of approach: 1) Directly paste the content in case statement echo area or 2) You can also call the external page by using include statement eg: include('home.php'); Hope it helps you Regards, Gonzo
Hi, ^ this info look okey... But i need to replace the main content when the ID is present. + Anyway write the content within the same file, but not to use echo, because i need to use HTML / PHP code within it? So when i use the ID string it replaces the main content with the Content box i request. If no ID string is requested = show main content.
In that case the method will be the same, just use "include" to call your content html file. eg: include ("content1.html"); and for main "main.html in default section of switch statement. Gonzo