Latest Update
Mikeplyts.net's Latest Update ™ shows the latest updates to the site. The updates are listed from the most latest (top) to the oldest (bottom). If you visit regularly, you should take a look here. Enjoy.

6/28/09: Brand new free image hosting script added under Resources section.
6/14/09: A bit of new graphics and photo captions added.
5/29/09: New DIV layouts added. (Still working on some more.)
4/7/09: Brand new website layout and javascript update.
3/21/09: Mpl.net Forums created.
2/14/09: New website layout and new div layout.
2/3/09: Major website and content update.
12/30/08: New website layout and php update.
12/28/08: Main website fully updated and running.
12/27/08: All main pages added/updated.
12/24/08: Main image(s) updated/added. Basic files and content updated/added.
12/23/08: Basic files and content updated/added.
12/22/08: Website created.

Affiliates
Free myspace layouts Disporatik

View All | Apply

Stats
eXTReMe Tracker
online
Add Mikeplyts On Myspace

TUTORIALS

• You do not have to leave credit but it would be greatly appreciated if you did.
• Make sure you have a basic understanding of HTML/CSS as well as PHP so that you can properly use these tutorials.

Photoshop Paint Shop Pro Photofiltre HTML/CSS PHP Javascript

PHP Includes with PHP Query Strings

Well, I was coding a few things last night, and stumbled upon a quite annoying problem. HOW DO YOU USE A PHP INCLUDE FOR A PHP QUERY STRING!?!?!? Let's Begin.


Basics: PHP Include

What are PHP includes?
A PHP include is a PHP code that allows the webmaster to 'include', or display, the contents of another .PHP file. These are generally used to construct pages that have the exact same content, except this way is faster to update the content and not having to manually update the content in HTML on every page. PHP Includes are very useful if your site has many pages. Hell, even these forums use PHP includes! They can be very reliable and helpful.

How can I use them?
First of all, you will need the PHP include code. It's a rather short code so no worries at all really. The only requirements for the PHP include to work are that the file you are going to display, MUST be a .PHP file and the file where you have the PHP include MUST be a .PHP file as well. Below is the PHP include code.

*FILENAME is the name of the .PHP file you're going to display.

Basics: PHP Query Strings

What are Query Strings?
A PHP Query String is a code that displays different variables with certain values in the URL bar due to the specified query values. In other words, it's the code that makes those nice little URL's like below:
Let's go over this URL in the next step.

What do the parts of the URL mean?
In the URL we displayed above as an example, there are some parts we should go over.

This is the file path to the .PHP file where you are going to display the query.

This is what states that there is going to be a query.


This the defined query string. You have a variable that is like a book, and the value which specifies the exact 'page' we want to see in the book.


This is an ampersand symbol which states that there is going to be another query string.


This is just another query string, except with a different variable and a different value.

Now let's see what makes this nice URL.

How can I use them?
The PHP Query String code will usually need a $_GET method, because we are trying to recieve, and not submit (using the $_POST method). In the $_GET method, you will define the variable and then the IF statement will be used to display what you got from the $_GET method, if you got anything at all. If you did get something, it will look for the value we specified and defined in the code. Once that happens, we then use ECHO to 'echo' the contents of that certain variable and value combination. Once we're done defining the variables and existing values to that variable, we will need to add an ELSE statement to display the error page because if there is something else that we didn't define and doesn't exist, it won't display and will generate an error. The only requirements are that the file you are using the PHP Query String in MUST be a .PHP file. Below is a simple PHP Query String code:

Just define the variables and define the appropriate values. *Note, you cannot use a DOUBLE QUOTATION MARK ( " ) unless you add a backslash ( \ ) before it, so it would be this - ( \" ). You may, however, use a SINGLE QUOTATION MARK ( ' ) without the backslash. We do this because since we are using the ECHO statement, we already have two double quotation marks, and if use another two inside the ECHO statement, then it will corrupt the code because it interferes with the double quotation marks used for the ECHO statement to display the content. And yes, you can display HTML/CSS in your content, but remember, you have to use SINGLE QUOTATION MARKS ( ' ) or DOUBLE QUOTATION MARKS WITH A BACKSLASH BEFORE IT ( \" ).
To add another value for the variable just keep adding this, but make sure it doesn't come before the ELSE (error) statement and that it is different from all the other values:


BUT WAIT!?!?! What if you want to display multiple different variables in the URL bar? Simply, just add the below on the same line on another ELSE IF statement.

You add that in between the parentheses and you add the below in between the multiple different variables in the code:


So now the code would look like this:




Advanced: Using PHP Includes inside of PHP Query Strings:

Why won't the PHP Include work?
So, what if you're trying to display the content of another page inside of your query string? You may have tried the below, right?

You see, the problem here is that we already have the question marks to begin the PHP Query String code, so including two more will just cancel them, thus canceling the PHP Include. The answer is very simple actually.

Since we already have the question marks to begin and end the PHP Query String code, we can also use different statements inside of the ELSE IF statements, which mean we can simply use the INCLUDE statement! First off, make another .PHP file first, and whatever content you have in one of your specified values, place it into the new .PHP file. Now instead of using this:

Just use this:

Now, you see how in the first code, we have this line to display what happens if you go to variable=value1:

Now, you'll notice the content1.php I included in the second code, that will contain the content I had when I was using the ECHO statement. So content1.php will look like this:

Also, if you use this method, you don't have to add a backslash ( \ ) before any double or single quotation marks. You can also even use PHP includes in that new .PHP file.

This leaves me to the last part of the tutorial, how to include a query string. As I've said before, you can't use a another question mark for the query string you're trying to display; since there already are two question marks for the PHP include. Once again, we will use the awesome $_GET method! All you have to do is this:

*Note, you MUST place the $_GET method first for it to work.




Hope that wasn't too confusing and helpful! If you have any problems, questions, or concerns, feel free to contact me. Thanks. :)

© Mikeplyts.net 2008-2009. All Rights Reserved.