I'm not too sure of how to explain these to you:
?page=content/page .. example
index.php?page=guestbookBut I will do my best.
I know them as
$_GET variables. To call this data you want to store use this code:
$_GET['page']$_GET is the method used, rather like
$_POST in forms.
To dynamically load pages which is what I think you want to do you want to store the $_GET['page'] in a variable like so:
$page = $_GET['page'];
With that variable, which will have the value of whatever is set in the url, which we discussed in this example would be
index.php?page=guestbook.
So, the variable
$page will have the value of
guestbook Depending on the method you want to use to load the page (i recommend include) you will need to append a file extension to the variable.
You can do this by either changing the variable $page from:
$page = $_GET['page'];
to
$page = $_GET['page'] . ".php";
Or by adding a new line which will append the extension. Like so:
// Add this below the first $page variable
$page .= ".php";
That will make the variable $page equal to $_GET['page'] with .php on the end of it
So with our example, if we were to echo out $page.. It would look like
// echo $page;
guestbook.php
Now that you have the page you wanted to load stored in the variable $page, you can proceed to include that page in your website with the following code:
// Including a page
include($page);
Alternatively you could use
require . Which is exactly the same as
include except, as the name suggests, whatever is "required" MUST exist for the script to continue. if it doesn't, it will throw back a fatal error and code below the require code will not be executed.
Creating hyperlinks to these pages is also simple. There is no special code, just put the URL in the hyperlink as you would expect it to look. Let's have a look at it with our guestbook example again.
// The hyperlink (in HTML)
<a href="index.php?page=guestbook">Visit my guestbook! :)</a>
And there you have it.
Loading Mysql data with that variable can also be done.
It looks a bit like this
(you don't need to append the extension).// Creating the variable of the page name.
$page = $_GET['page'];
// Creating the connection handler
$connection = mysql_connect("host","username","pass");
// Selecting the database
mysql_select_db("database_name",$connection) or die ("Could not select database");
// Creating the query, remember, double quotes are non-literal so you can include variables inside of them and they will work properly, unlike single quotes.
$query = "SELECT content FROM pages WHERE page_name = $page";
// Storing the content inside the variable $content
$content = mysql_query($query) or die (mysql_error());
// echo'ing out the content stored in $content
echo $content;
I hope that makes sense. It made sense my head atleast haha
Edited by Sp0nge, 01 July 2008 - 12:14 AM.