![]() |
Php Tutorial 2
Hi, if you are viewing this tutorial I am hoping that you have looked over tutorial #1 as it is essential that it is done, otherwise I think you will be completely lost.
~SyringeX What's all the advanced stuff your going to teach me? Well, I don't think we're quite done with The Basics yet, and we won't be starting MySQL until either lesson 3 or lesson 4. In this tutorial, you'll be learning things that will help you maintain an easier web site. What will help me maintain an easier website? Well, first of all, your variables will, we already covered those, and will be working with them a bit more in this tutorial. We are also going to be looking over includes, one of the best commands in php. Alright, open up notepad and get ready. Let's take a look at the simple include statement. What the include statement does is include an external file from one of your folders. How would this help maintain an easier layout? Well, let's say you had your navigation links table. You have about 50 pages, and you want to add a new link. You could add the link on each page, but that would be very tedious, this is where includes come in handy. By including a file named navigation.php that you've created, you can simply add the link in the navigation.php file, and all your pages with the included navigation.php page would then have that link! (navigation.php must be made manually, and should be constructed the same as your navigation table, without any other features) Let's look at the include statement code: :
Save it, open it up. Cool huh? If it didn't work, make sure you have a navigation.php file made with your nav table on it. You need to make sure it's in the same directory as the file with the include on it, otherwise you'll have to specify the folder it is inside. EX: :
Can I make everything else easier by creating a php layout? YES. I highly recommend using includes. Things that often use includes are your navigation tables, tagboard and polls tables, headers and footers, and other optional information. Let's take a look at how we can construct this simple php layout. :
Make sure when you do this that you have the separate files that you want created on here. That pretty much does it for the include statement, so let's take a look at a new one. Now we are going to look at the IF statement The IF statement is also a very important part of php. It reads to see if a part of a script is equal to, less than, or greater than something else. Depending on the answer, it releases different information. Let's look at the basic construct of an IF statement: :
So basically, if whatever is inside the parentheses are true (also known as 1) all information from the first bracer to the closing bracer will be submitted, otherwise everything after the else bracer to the ending bracer will be submitted. Try playing around with the IF statement a bit and see what you can come up with. If you've seen the generators I've created, a big part of these are using IF statements. You can also check to see if two variables are equal to eachother: :
Cool isn't it? Now we are going to move on to the wonderful and delightful world of... Functions! Functions help save time, and a good ton of it. They allow you to store code that can be called by typing in the functions name followed by your parenthese ();. Let's take a look at declaring, and then calling our function: :
Pretty easy isn't it? Everything within the braces is the value of the function. It doesn't have to be just text, it can be variables with the your mysql user settings, cookies, sessions and so on. They come in handy for portal and game making. And to call it, all's you do is type the name of your function, followed by parentheses and semicolon, and you're done! This is pretty much it for lesson 2, soon we'll be hitting the advanced things, but look below for this lesson's Cool Script! Cool Script! This lesson's cool script is a hit counter. All's you have to do is create a file called hits.txt -- Insert the number 1 on it, and that is all. Then type in the following code, which will use a blend of some of the aspects we've talked about. It adds 1 everytime a page is opened to hits.txt, giving us a hit counter! Once you've created the actual hit counter file, include it by using the include statement (You ought to know how by now B) ) :
Created by Syringex |
I need help in the arrays turorial
Could someone help me figure out what is wrong. I tryed everything in the turorial and it did not work. :mad:
|
I was wondering if you could edit in which one is the first tutorial :) I figured them out. Just for future reference though.
|
| All times are GMT -5. The time now is 12:43 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC