|
|
#1 (permalink) Top |
|
Alpha Geek
![]() Join Date: Apr 2004
Age: 20 Male
Posts: 2,270
Times Helpful: 51
My Mood: Angelic
Status: Offline
|
This tutorial is for anyone who has never touched PHP coding before...if you have, you'll find it kind of basic, but I will guide you through installing, and creating several basic scripts to get a feel for the language.
It would help if you know HTML, but this is not necessary for this tutorial. Step One Firstly, you will need to obtain access to a PHP Capable server. Don't fear, for if you do not have access to a suitable web server, for there are plenty of easy options for creating scripts offline. If you don't have access, then head on over to Apache Friends and download yourself a copy of Xampp. This brilliant program will fully install and configure PHP, MySQL and Apache Web Server on to your computer. Download, install the program. Install MySQL and Apache as services. Once installation is complete, point your browser over to: http://localhost/ and if the installation was successful, you will see the Xampp welcome screen. Choose your language, and you are ready to go. Navigate on the left - you can access phpMyAdmin, the internet standard for creating and managing SQL Databases, but for now, we aren't worried about that. Step Two You are ready to begin coding your first PHP script. Open up notepad or dreamweaver, or essentially any text application. Start a new document, and type in the following: PHP Code:
C:\Program Files\xampp\xampp\htdocs (I would suggest making a new folder for your scripts, so maybe: C:\Program Files\xampp\xampp\htdocs\myphp\) now, point your browser over to: http://localhost/firstscript.php or if you saved it in a folder.. http://localhost/myphp/firstscript.php Hopefully, if all has gone well, you will see the following: Code:
This is my first script! If you do, however, then, move on. Step Three PHP Code is a server side scripting language...all the content is dynamic and so everything is carried out on the server before being sent to the browser, as HTML. This means that your code is safe from people trying to steal it, and it enables you to do some awesome things with websites and applications. The basic syntax is: PHP Code:
PHP Code:
Variables are a crucial part in any language, and PHP is no exception. Variables are declared like this: PHP Code:
PHP Code:
These are vital for any application to have more than one possiblity, based on whether or not an arguement is true or false. the strucutre for an IF/Else is: PHP Code:
If something is true/false (it can be either, or something more advanced such as if a value is present), then do something. Else, if this is not true, then execute something else. It's easier in practice. Load a new script: PHP Code:
You should be displayed with the first message. Now go back to the script and change the name in $name, to some random crap. Now run the script again. As the $name is no longer equal to (==) "Waffles", the other code is executed. And there we have..very, very, basic PHP. |
|
|
|
|
#2 (permalink) Top |
|
Administrator
![]() Join Date: Oct 2001
Age: 24 Male
Posts: 4,380
Times Helpful: 114
My Mood: Meh
Status: Offline
|
basic is where it all starts, good tutorial dude! I was wanting to write some php tutorials, since its something I could write about without...maybe after my exams.
__________________
Zone 365 | F@H Team | Team Stats | Use The Thank You System | My Groups: Manchester United | Apple |
|
|
|
|
#3 (permalink) Top |
|
The King
![]() ![]() Join Date: Jan 2004
Age: 18 Male
Posts: 5,254
Times Helpful: 402
My Mood: Drunk
Status: Offline
|
Good tutorial.
Carrying on from if statements...Every statement should be terminated with a ;. Because the PHP interpreter program ignores whitespace characters during coding then it is important to remember to terminate every statement. e.g.: PHP Code:
__________________
Never trust a program you don't have the source code for. ![]() My website | Powerful Desktop Linux | Linux for human beings | Linux for power users | Linux for ricers |
|
|
|
|
#4 (permalink) Top |
|
Nonconformist Geek
![]() |
* Stickied *
__________________
See My Desktop | Try Linux | Install Linux | Visit My Server | Support Hardware Forums | Easily rip DVDs in Linux |
|
|
|
|
#5 (permalink) Top |
|
Alpha Geek
![]() Join Date: Apr 2004
Age: 20 Male
Posts: 2,270
Times Helpful: 51
My Mood: Angelic
Status: Offline
|
Time for an update..not so much beginners, but just random PHP Stuff.
Functions Functions, are either: Prebuilt into the code of a given language, and (usually), return values when parameters are passed into them. They can also be defined by a programmer, to create useful shorthand pieces of code, that can be reused quickly and easily. Some existing PHP Functions At last count, some 3000+ functions are built into PHP (the latest version anyway). They are constantly being expanded, as new versions/releases are brought out. A function is structured like this: PHP Code:
echo() - is used to display output to the web browser. It is not strictly a function however, it is a language construct. It cannot return a value, but is considered a faster operation than the alternative, Print. Print works largely the same as Echo, except Print can return a value ( True/False). It is also said to be slower in execution, however the difference is 1000's of miniseconds, and so this is barely worth mentioning. Both will return the data entered between the parentheses to the browser (although echo does not require the ()'s, it will operate with just quotation marks). PHP Code:
------------------- strtolower($string); - self explanatory - String to Lower (case), presumably. example usage: PHP Code:
I believe this is recursive coding...using the same variable again, but in like an updated form. (vague explanation admittedly) ------------ Now, to create your own function.. First you need to tell PHP you are starting a function, then give it a name: PHP Code:
You must then decide what you want your function to do. I have coded a handy function, that allows the coder to enter the name of a database, and a table within, and have the number of rows returned to the screen (this is useful when counting say, the number of members, or tutorials a database has.) Rather than type out lengthy SQL queries, several times, the function can be used multiple times, with different table/database names to return the row count. I will call the function "CountRows", and I need only 2 variables (it's basic). that would be, the database name, and the table name. PHP Code:
PHP Code:
in order to use this, we would first include the function code on the page we are working, and then: PHP Code:
I would probably extend this by throwing in some error handling, like what happens if the user can't connect to MYSQL or chooses an invalid table/db name. But providing you enter the correct info, you will be able to count any row, in any table, in any database. Hope this helps. |
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| beginner with AC97 problems | bazza | Sound Cards and Speakers | 2 | 24-04-2005 11:06 AM |
| I'm a beginner when it comes to computers | steveaslin | General Hardware | 2 | 18-04-2005 08:51 AM |
| Sig Tutorial | Waffle | Tutorials | 21 | 10-12-2004 09:23 PM |
| SATA help for a beginner | mattymeik | Storage Devices | 1 | 06-10-2004 02:08 PM |