Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works


  • Please log in to reply

Mr. Jack

Mr. Jack


  • Member
  • PipPip
  • 92 posts
I know this might be a stupid question...but I am sick and tired of updating my entire website every time I need to make a single change to the layout or color.

I know that I could use SSI, but I have heard that is slows down the loading of pages and such. I have read a few books on PHP and MYSQL, and I understand the basic code, but I need help on how it is put into use.

Like I have noticed on some sites, after the document or page it has something like this:


I just don't get how to do things like that, for example: creating a page that when I change the top or the colors, that it will change everything.

How do major websites like Digg or even this one code their websites? Do they code each portion with html or php and put it in the database or is the database even in effect or helping with the design at all? I need someone to help me with this.

If you guys could find me a script or just explain it to me, it would help tons.


Edited by Mr. Jack, 07 May 2008 - 07:38 PM.

  • 0




    Spyware Veteran

  • GeekU Moderator
  • 32,332 posts
To style your site different pages at once, the easiest to use, at least in my opinion is a stylesheet.
A good place to start studying how these css stylesheets work is

Also worth a visit:

I hope this helps you on your way. :)
  • 0



    New Member

  • Member
  • Pip
  • 3 posts
CSS is the best way to make simple updates to changes like color or layout. If you are wanting to make site wide changes to a certain part (like navigation links or a header/footer) I would recomend creating that in a seperate file and using include('file.php'). That way you can change 'file.php' and the changes will show on all of your pages.
  • 0



    New Member

  • Member
  • Pip
  • 1 posts
Or maybe a PHP Templating System would do the trick, easily and instantly!
have you tried smarty? http://php.smarty.net
  • 0




  • Member
  • PipPip
  • 90 posts
I'm not too sure of how to explain these to you:

.. example index.php?page=guestbook

But I will do my best.

I know them as $_GET variables. To call this data you want to store use this code:


$_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'];
$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;

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

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.

  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP