Help with PHP and displaying pages

Join Discord

Far

tsniffer
Staff member
Developer
May 19, 2003
20,179
30
2,783
540
I've got a lot of tutorials i want to put on to a website, each on a different page but using the same php file.

for example i want my address to be games\tutorials.php?id=minecraft or games\tutorials.php?id=Skyrim.

The tutorials all have different layout formats (different amount of headings ect)

The tutorials will be written by myself, but id rather have a single page than 1000 pages for the webpages. (makes it very hard to edit)

Does anyone know the best possible way i can easily implement this design? I thought about adding the contents and headings in to an sql table, but i didn't think bulk text worked that well in table form.

I can use php/html/css/sql.
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,179
30
2,783
540
why are you linking me to the console gaming section :S
 

Tai

HEAD CAPTAIN
Staff member
Administrator
May 11, 2003
14,311
2
2,694
515
United Kingdom
lol, it was a subtle/bad attempt at saying "post your guides here"

/ilied
 

JealY

LOMCN VIP
VIP
Nov 28, 2004
5,354
52
305
England
Right, I hope this doesn't need much explaining because... I don't want to! It's pretty self explanatory really.

You would put this where you want the page to be;
PHP:
<?php
switch ($HTTP_GET_VARS[id]) {
default:
include "default.php";
break;

case 'minecraft':
include 'minecraft.php';
break;
}
?>
For every page to be "included" you just add a
PHP:
case 'xyz':
include 'xyz.php';
break;

Then you just use website.php?id=minecraft or whatever.
 
Last edited:

Far

tsniffer
Staff member
Developer
May 19, 2003
20,179
30
2,783
540
ah i get it. yeah thats kinda what i was thinking, but my thought was to have them as .txt files, i can actually see having them as php makes it more logical.

so basically if the included file is named pron.php, i'd just have website.php?id=pron and it would include that?

@Thai, after you explained the joke i got its relevancy, it was kinda lols.

EDIT:

changed the code to this and works perfectly so far.

PHP:
<?php

$adr = $_GET["id"];
$var = '.php';

include "$adr$var";
break;


?>

thanks again :) Now i just need to think of a way to make it more complex.

I want it to ideally search through folders to find the include.

so if i type website.php?id=mir

it would look in games/mmo/ to find the mir.php file

but if i type website.php?id=pron

it would look in pron/sexytime/ to find pron.php file

Want to do this so i can organise the tutorials in to sections and not just have 1000's in a single folder.
any ideas?
 
Last edited by a moderator:

JealY

LOMCN VIP
VIP
Nov 28, 2004
5,354
52
305
England
Glad you figured it.

Not sure how to include heirarchys really unless you had some sort of database or some querys to find where the file is.
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,179
30
2,783
540
got that sorted :) my next step is to split up the directory, so i can write the address in the header.

PHP:
<?php
//Searches all forward directories, gets the path and file name, then includes it if it matches ?id=

filesInDir('includes/tutorials/');

function filesInDir($tdir)
{
$adr = $_GET["id"];
$ext = '.php';
$adrext = $adr . $ext;

        $dirs = scandir($tdir);
        foreach($dirs as $file)
        {
                if (($file == '.')||($file == '..'))
                {
                }
                elseif (is_dir($tdir.'/'.$file))
                {
                        filesInDir($tdir.'/'.$file);
                }

		if ($file == $adrext)
		{
			include $tdir.'/'.$file;
		}
        }
}
?>