Forum Moderators: coopster

Message Too Old, No Replies

includes in conjunction with if statements and href

         

derek mcgilvray

8:33 pm on Apr 8, 2007 (gmt 0)

10+ Year Member



Just a quickie - is it possible to use includes in conjunction with if statements and href links?

For example:
if (i click on 'page 1'), include 'page1.php'
if (i click on 'page 2'), include 'page2.php'
etc.

If so, please tell me how! cos I can't find it myself.

eelixduppy

8:37 pm on Apr 8, 2007 (gmt 0)



Although this thread [webmasterworld.com] doesn't directly relate to your question, the code being used is doing just what you are asking. You can use uri queries and the $_GET superglobal to include different files. quick example:

$page = $_GET['page'];
switch($page) {
case 'one':
include('/one.html');
break;
case 'two':
include('/two.html');'
break;
default:
include('/default_page.html');
}

Good luck! :)

derek mcgilvray

8:45 pm on Apr 8, 2007 (gmt 0)

10+ Year Member



Thanks for that super-quick reply - I will let you know how I get on with this.

derek mcgilvray

8:54 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



Thanks for your help earlier Eelixduppy, with a bit of fiddling it worked out well. Here is a working bit of code that may prove useful for someone else in the same situation:

<?php
echo"<table><tr><td>";
echo"<a href=\"?x=cd\">Change your details</a></td><td>";
echo"<a href=\"?x=cp\">Change your password</a></td><td>";
echo"<a href=\"?x=a\">Add items</a></td><td>";
echo"<a href=\"?x=dd\">Delete an item</a></td><td>";
echo"</tr></table>";

$x = $_GET['x'];
switch($x) {

default:
echo"default text";
break;

case 'cp':
include ("change_password.php");
break;

case 'cd':
include ("change_details.php");
break;

case 'a':
include ("add.php");
break;

case 'dd':
include ("display_delete.php");
break;
}

?>