Klance Posted April 3, 2008 Share Posted April 3, 2008 Ok so I have a page called index.php that has this: <?php if(!empty($_GET['id']) && file_exists("./$_GET[id].php")){ include("./$_GET[id].php"); } ?> <a href="?id=hello">Hello Page</a> then that makes a page called index.php?id=hello Now, I want a page to come off of that so that it would be index.php?id=hello&id2=goodbye I've tried to just put this in hello.php: <?php if(!empty($_GET['id2']) && file_exists("./$_GET[id2].php")){ include("./$_GET[id2].php"); } ?> <a href="?id2=goodbye">Goodbye Page</a> and i figured it would just build off of index.php?id=hello but it just makes index.php?id=goodbye Should I use the $_SERVER['PHP_SELF'] feature? I'm not too sure what to do here. Quote Link to comment Share on other sites More sharing options...
devstudio Posted April 3, 2008 Share Posted April 3, 2008 Lots of solutions here. You *could* append to $_SERVER[REQUEST_URI]. <a href="<?=$_SERVER[REQUEST_URI]?>&id2=goodbye">Goodbye Page</a> ... It looks like you may just be learning. But you may want to modify your logic so "id" doesn't change (also, perhaps the variable name "action" maybe better) then use switch statements. <?php if(!empty($_GET['id']) && file_exists("./$_GET[id].php")){ include("./$_GET[id].php"); } switch($_GET['id']) { case 'hello': echo "<a href=\"?id=hello\">Hello Page</a>"; break; case 'goodbye': echo "<a href=\"?id=goodbye\">Goodbye Page</a>"; break; } ?> Best, Nathan Quote Link to comment Share on other sites More sharing options...
Klance Posted April 3, 2008 Author Share Posted April 3, 2008 Lots of solutions here. You *could* append to $_SERVER[REQUEST_URI]. <a href="<?=$_SERVER[REQUEST_URI]?>&id2=goodbye">Goodbye Page</a> ... It looks like you may just be learning. But you may want to modify your logic so "id" doesn't change (also, perhaps the variable name "action" maybe better) then use switch statements. <?php if(!empty($_GET['id']) && file_exists("./$_GET[id].php")){ include("./$_GET[id].php"); } switch($_GET['id']) { case 'hello': echo "<a href=\"?id=hello\">Hello Page</a>"; break; case 'goodbye': echo "<a href=\"?id=goodbye\">Goodbye Page</a>"; break; } ?> Best, Nathan The reason I don't want to use the switch-case method is because i'm trying to get it to build off eachother, to get an effect like this: http://www.scorehero.com/top_scores.php Quote Link to comment Share on other sites More sharing options...
devstudio Posted April 3, 2008 Share Posted April 3, 2008 In that case, you can use the REQUEST_URI, as explained in the first example. However if it is to be architected like the example link, I would still use the switch case to determine what main "action" they are performing and then in the suburl's just include what is relevant from the current information. <?php if(!empty($_GET['id']) && file_exists("./$_GET[id].php")){ include("./$_GET[id].php"); } print("<a href=\"?id=hello\">Hello Page</a> | <a href=\"?id=goodbye\">Goodbye Page</a><br><br>"); switch($_GET['id']) { case 'hello': break; echo "<a href=\"?id=".$_GET['id']."&sub_id=Bob\">Hello Bob</a>"; echo "<a href=\"?id=".$_GET['id']."&sub_id=John\">Hello John</a>"; case 'goodbye': echo "<a href=\"?id=".$_GET['id']."&sub_id=Bob\">Goodbye Bob</a>"; echo "<a href=\"?id=".$_GET['id']."&sub_id=John\">Goodbye John</a>"; break; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.