Jump to content

Different content showing on one page


Xoom3r

Recommended Posts

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

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

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.

 

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"

 

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);
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.