Code Strategies for the PHP Fourm

 

This lesson is part of an ongoing Foruml tutorial. The first part is here: Build your own Forum, along with all the files you need.

There are a lot more PHP pages for this forum project than there were for the other projects you have tackled. But the strategy that is used for this project is more or less the same for all pages. Here's what we'll be doing:
  • A user clicks on a link on a forum page
  • The hyperlink will contain a variable that we can use to access our database tables
  • Take this code and pull records from the table

As an example, take the Microsoft Word Forum. You saw that the hyperlink in the status bar is this, when you hold your mouse over it:

pageThread.php?sID=secWP

The page the user will be taken to is called pageThread.php. But we want to take some information to this page (which forum the user asked for). This is done by adding a question mark after pageThread.php. The question mark tells PHP that there is some GET data to follow. You then type a variable name (sID, for us). After an equals sign ( = ) you type what is going into the variable name (secWP, in the hyperlink above).

When pageThread.php is loaded, we can grab that sID variable and do something with it.

This, then, is the strategy we'll use for most of the forum – pass variables to other pages by using GET data. We need to do this because there is no easy way to hand variable information from one page to the next. You could write a cookie, or set up some session variables. But the technique we're using is a common one, and is widely used on the internet. There's a good chance you'll need to do this in your own projects, so it's well worth learning.

To begin the forum walkthrough, we'll take a look at the main page of the forum – forumTest.php. This is in the next part.