Xoom3r Posted April 10, 2008 Share Posted April 10, 2008 Hey people, I didn't even knew that I'm registered here.. Anyways, I work with bits of PHP lately and I have a small roadblock. I am trying to find a tutorial that explains how to make things like this: viewtutorial.php?tut=38210 That the content on the page will be shown by the ?tut=38210 command. And yes, I'm a total PHP nub, the only thing I know is <?php include('news/news.txt') ?> Though I'm a very good HTML coder. Link to comment https://forums.phpfreaks.com/topic/100497-different-content-showing-on-one-page/ Share on other sites More sharing options...
craygo Posted April 10, 2008 Share Posted April 10, 2008 ok lets say you have your base page called viewtutorial.php and you want to show content that is in 38210.php so viewtutorial.php will look something like this <?php if(isset($_GET['tut'])){ // assign page in the url $page = $_GET['tut'].".php"; } else { // show a default page $page = "default.php"; } include($page); ?> Ray Link to comment https://forums.phpfreaks.com/topic/100497-different-content-showing-on-one-page/#findComment-513939 Share on other sites More sharing options...
Xoom3r Posted April 10, 2008 Author Share Posted April 10, 2008 OK, Thanks.. I'll try that right now, if it won't work, I'll be back with more Q's! Link to comment https://forums.phpfreaks.com/topic/100497-different-content-showing-on-one-page/#findComment-513946 Share on other sites More sharing options...
poleposters Posted April 10, 2008 Share Posted April 10, 2008 Hey, not exactly sure what you're trying to ask. But I have a hunch. I'm guessing you want to pull a tutorial with the id tut=38210 from a database to display on the page viewtutorial.php. The way it works is, you have a link viewtutorial.php?tut=38210 When this link is clicked you go to the viewtutorial.php page. the tut=38210 is a GET paramater. So in your script you need to test if this parameter exists then you can place into a variable to use in your database query ie if(isset($_GET['tut']) { $tutorial=$_GET['tut']; } this puts the number 38210 into the variable $tutorial. Then you have to search the database for the row where the tutorial_id=$tutorial. Once you have extracted this you can place it into an array and use some code to display the tutorial. If you post some code, I can help you. Link to comment https://forums.phpfreaks.com/topic/100497-different-content-showing-on-one-page/#findComment-513953 Share on other sites More sharing options...
Xoom3r Posted April 10, 2008 Author Share Posted April 10, 2008 No thanks, craygo helped me! it's working (with few minor changes though ) THANKS! - Solved. Link to comment https://forums.phpfreaks.com/topic/100497-different-content-showing-on-one-page/#findComment-513956 Share on other sites More sharing options...
Xoom3r Posted April 10, 2008 Author Share Posted April 10, 2008 Oh wait, I still need some help.. This is OK: <?php if(isset($_GET['tut'])){ // assign page in the url $page = $_GET['tut'].".txt"; } else { // show a default page $page = "index.txt"; } include($page); ?> But is thee any way to set a custom title that will be set in the .txt file? That if I want the title to be "Spawning Enemies" then it will be set in the .txt file.. Like that: $title = "Spawning Enemies" Link to comment https://forums.phpfreaks.com/topic/100497-different-content-showing-on-one-page/#findComment-513966 Share on other sites More sharing options...
Zhadus Posted April 10, 2008 Share Posted April 10, 2008 Make a header file with: <?php echo "<title>$title</title>"; ?> And have the header included in the text using include(). Just define $title as whatever you want BEFORE you put in the header include. Example: <?php $title = "My Title"; include(header.txt); ?> Link to comment https://forums.phpfreaks.com/topic/100497-different-content-showing-on-one-page/#findComment-513970 Share on other sites More sharing options...
craygo Posted April 10, 2008 Share Posted April 10, 2008 OK you might like this one. You can setup an array of your page either on the main page or in another file but something like this <?php function pagetitle($page){ $parray = array("Page 1 Title" => "38210.php", "Page 2 title" => "38211.php"); return array_search($page, $parray); } now you can add it to the main page. <?php function pagetitle($page){ $parray = array("Page 1 Title" => "38210.php", "Page 2 title" => "38211.php"); return array_search($page, $parray); } if(isset($_GET['tut'])){ // assign page in the url $page = $_GET['tut'].".txt"; } else { // show a default page $page = "index.txt"; } ?> <html> <head> <title><?php echo pagetitle($page); ?></title> </head> <body> <p align=center>Welcome to <?php echo pagetitle($page); ?> page</p> <?php include($page); ?> </body> </html> Something like that Ray Link to comment https://forums.phpfreaks.com/topic/100497-different-content-showing-on-one-page/#findComment-513972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.