index.php?page=aboutme

April 26, 2002 by  
Filed under Code Snippets

I recieved an email yesterday about this:
Hi,

I visited your site daynah.net, very nice site you got :) I very curious how do you ppl extract data from a
database like ‘index.php?page=aboutme’. I read through php.net which some of them refer me and i don’t find very good page on the site to teach me on that. I currently have a database (mySQL) so i can try it out :) but i need some guide, im very new to it =)

Would you mind to guide me with how to extract data on the database and do a link like ‘index.php?page=aboutme’? I really very curious about it..heh.

Hope to hear from you soon,
Edward

—————

Hello there curious Edward. ;) A lot of people have been asking me this, so I decided to post it up to share . The coding is pretty simple. And this is only one way of doing it.

In your index.php page, put in this:

<?
  if($page == 'aboutme')
    include('aboutme.php');
  else if($page == 'downloads')
    include('downloads.php');
  else
    include('main.php');

?>

now create other files called aboutme.php, downloads.php, and main.php. And put something in them like “this is the about me page,” “this is the downloads page,” etc.

Go to your url, http://yourdomain.com/index.php?page=aboutme What do you see?

So.. is that simple? :) Another note, the pages don’t have to be aboutme.php… it can also be aboutme.txt of aboutme.html, or rename it to anything else if you like. And a mysql database is not required at all. I hope that helps.

Related Posts Plugin for WordPress, Blogger...
  • Edward

    Thanks. just curious, u happen to know how this guy did this? “http://www.jerrett.net/?X=me”

  • Edward

    Thanks. just curious, u happen to know how this guy did this? “http://www.jerrett.net/?X=me”

  • http://daynah.net Daynah

    yes, change $page to $X

  • http://daynah.net Daynah

    yes, change $page to $X

  • http://turtelina.net Connie

    Hey Daynah, Awesome! I always wanted to know how you do that. :-D

  • http://turtelina.net Connie

    Hey Daynah, Awesome! I always wanted to know how you do that. :-D

  • http://ecila.fallinside.org/b2/ ecila

    hahaha wow! i always wanted to know that! hahaa XD i’ve learned something!

  • http://ecila.fallinside.org/b2/ ecila

    hahaha wow! i always wanted to know that! hahaa XD i’ve learned something!

  • Edward

    Hi! :) How do call from sub folder like

    “include(‘../images/index.php’);” i tired this, but cant work. How do call from sub dir? :)

  • Edward

    Hi! :) How do call from sub folder like

    “include(‘../images/index.php’);” i tired this, but cant work. How do call from sub dir? :)

  • http://daynah.net Daynah

    Well, if you’re doing it the same way I’m showing above, then it should be include(‘images/index.php’); Make sure the path is correct, else it’ll give you an error saying file not found, or file cannot be included.

  • http://daynah.net Daynah

    Well, if you’re doing it the same way I’m showing above, then it should be include(‘images/index.php’); Make sure the path is correct, else it’ll give you an error saying file not found, or file cannot be included.

  • Edward

    Ok, got it. Thanks :)

  • Edward

    Ok, got it. Thanks :)

  • http://faltering.net ina

    i don’t do it that way.
    all i do is to put

    on my index.php-file. then I create a .txt file for the text on the index page, and other txt-files. The adress I get to a subpage is then index.php?p=something…

  • http://faltering.net ina

    i don’t do it that way.
    all i do is to put

    on my index.php-file. then I create a .txt file for the text on the index page, and other txt-files. The adress I get to a subpage is then index.php?p=something…

  • http://faltering.net ina

    this is what I put in the index.php file(without the *)

  • http://faltering.net ina

    this is what I put in the index.php file(without the *)

  • http://faltering.net ina
  • http://faltering.net ina

    ok, I messed everything up now…
    http://faltering.net/index.php?p=php

  • http://faltering.net ina

    ok, I messed everything up now…
    http://faltering.net/index.php?p=php

  • http://daynah.net Daynah

    That’s a great way of doing it too. But the reason I do if and else is because I like to keep previous versions of my layouts.

    So I can put something like
    if($page == ‘aboutme)
    include(‘version2/aboutme.php’)

    That way, if the pages vary also, I can keep those changes. ;) But you’re right, the best way is what you’re doing. Just make sure you do a check for if the file exist or not. :)

  • http://daynah.net Daynah

    That’s a great way of doing it too. But the reason I do if and else is because I like to keep previous versions of my layouts.

    So I can put something like
    if($page == ‘aboutme)
    include(‘version2/aboutme.php’)

    That way, if the pages vary also, I can keep those changes. ;) But you’re right, the best way is what you’re doing. Just make sure you do a check for if the file exist or not. :)

  • http://daynah.net Daynah

    You won’t believe that I woke up at 3am and started typing up a more efficent script would you?

  • http://daynah.net Daynah

    Well, here it is: http://www.php-princess.net/board/viewthread.php?tid=7 Zip file and all. :) Enjoy!

  • http://daynah.net Daynah

    You won’t believe that I woke up at 3am and started typing up a more efficent script would you?

  • http://daynah.net Daynah

    Well, here it is: http://www.php-princess.net/board/viewthread.php?tid=7 Zip file and all. :) Enjoy!

  • Billy

    Another way to successfully achieve the behaviour discussed here w/o the necessity of a template driven site is to use php’s switch in conjuction with Header location: rather than an include.

  • Billy

    Another way to successfully achieve the behaviour discussed here w/o the necessity of a template driven site is to use php’s switch in conjuction with Header location: rather than an include.