Includes... and if statments?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fatima
Forum Newbie
Posts: 1
Joined: Thu Jul 14, 2005 6:28 am

Includes... and if statments?

Post by Fatima »

Hello,
I've read several tutorials on php before and I have mostly worked with includes for web site purposes.

Now, however, I need to create a website for books to be viewed online. And making a separate php file for each page of the book(s) is not what I would like to go through. Instead, I thought, there must be a way to just "switch" one part of the website for another - meaning switch on include for another.

So if a person was reading book 1, and clicked on the page 4 link, then the url would look something like books.php?id=1&page=4 and the page include would change to load page 4.

Some one recommended if statements, but I can't seem to get them to work. I understand what they are, but how will they help my website? Most tutorials I have visited on the net talk about if statements for programming purposes and databases.

Any help or a push in the right direction would be most welcome.
I hope my english is clear enough, and sorry if it isn't.
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

Post by dstefani »

Hello,

If your 'books online' project is time sensitive, you may want to hire someone to help you.
If not, then buy a beginners PHP book and begin studying and looking at other peoples code
to see how they do things.

- dstefani
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

switch ($_GET['book'])
{
    case "some_book":
        include('some_book/'.$_GET['page'].'.html');//tweak this
        break;
    case "other_book":
        include('other_book'.$_GET['page'].'.html');
        break;
    default:
        include('index.php');
}
see where im going with this? you will only have to have the html page for each page in the book. there are many other ways to do this like load the entire book into a single page then using define() to define a number to a block of text and doing case switch for the id then echoing the id wich would be a defined page with the id number...but maybe thats a little confusing for you right now.
Post Reply