Mushroom5698
05-09-2004, 04:15 AM
Guide to this tutorial...
Reading this guide, it is assumed that you know absoutely NOTHING about php scripting...
Table of Contents:
Chapter 1. How to run a PHP script...
Chapter 2. The most basic of PHP scripting...
Chapter 3. Randomize...
Chapter 4. If/elseif/else commands... Allows your script to check stuff...
Chapter 5. The harder stuff... MYSQL! (full tutorial on EVERYTHING mysql
Chapter 6. Ill think of what I want for chapter 6, later, and when I do, ill post it.
Chapter 1 - How to run a PHP script...
Ok, if you are totally clueless on what a PHP script is, does, and how to use it, read this...
A PHP script IS a server side scripting language... In english, this meens that the person viewing the website won't get to see whats happening, unless you allow a way for them to see it...
A PHP script DOES just about anything you want it too...
To use a PHP script you must have a website... This website must have PHP enabled on it. If you are not sure if your website has php enabled, contact your provider... To use it you must upload a .php file to the server, and than run it in your browser.
Any questions? If so, please email me at Mushroom5698@aol.com and ill reply... If not, move on...
Chapter 2 - The most basic of PHP scripting...
This is the MOST BASIC script you could ever make... Ill go over it step by step in just a few seconeds...
<?php
echo("Hello, World!");
?>
On your computer, goto start, run, and type notepad. Copy and paste this code in notepad. Save the file as "hi.php" (include the quotes!). Upload this file to your website, and view it in your browser... Do you get what it does? If not, this is how it works...
<?php - This starts your PHP script... EVERY php script you make, will begin with this...
echo("Hello, World"); - this prints "Hello, World" in the browser
?> - This ends your PHP script... EVERY php script you make, will end with this...
Get it? If not please email me at Mushroom5698@aol.com, and I will help you with what ever you don't understand... If you understand it, go on...
Another basic thing in a PHP script you should know, is making notes... Here is a PHP script...
<?php
//This is a note
?>
What does this script do? Nothing... But, lets say you write a PHP script, and your not sure if you'll remember what everything does... Just put notes everywhere in the script, about what the next line does...
So, that is very basic stuff, yet, if you do not get it, send me an email!
Chapter 3 - Randomize!
Ok, it seems like there are SOOOO many people who want to know how to randomize stuff! Well, heres a very simple way...
Firstly, let me introduce arrays. Arrays, are just more than one value assigned to one variable... OH! I forgot to tell you how to make variables...
Ok, lets say you wanted to make a variable...
$hi = "hello";
Simple, right? That meens that whenever you typed $hi it would return hello... An example...
<?php
$hi = "hello, world";
echo "This is an example of a variable: $hi";
?>
Would print on the screen: This is an example of a variable: hello, world
Get it? If not email me!
Now, back to arrays... Lets say you wanted to store a list of colors, in one variable... You have to make an array, useing the FUNCTION array...
$colors = array("black","blue","green","red","yellow");
So, whenever you reference to $colors[0] you would get black... $colors[1] would be blue, $colors[2] would be green, and so on...
So, lets say we wanted to get a random color, and print it to the screen...
First we have to learn something new! The funcion array_rand
array_rand
Here is a sample code for it...
array_rand($colors, 1);
The $colors part tells it that the array were dealing with is called "colors"... The part the say 1, is telling it to pick out ONE random choice... This function will only return a number, however... We have to put that number in the array... At this point, it gets a little more complicated, but ill explain it to the best of my ability...
<?php
// Create an array stored in the variable called "colors"
$colors = array("black","blue","yellow","white");
// Get 1 random part of the array... (this will return 0 1 2 or 3)
$random_number = array_rand($colors,1);
// This is where it gets a little tricky... You remember how I said that if you
// Wanted to reference the "blue" in this array, you would have to reference
// $colors[1]..? Well, with this random thing its the same... Only, instead of
// saying one, we will reference $colors[$random_number]
// and store it in a variable called $result
$result = $colors[$random_number];
echo $result
?>
Thats all 4 this chapter... If you have any questions, email me at Mushroom5698@aol.com... Ill answer them all to the best of my ability...
Ill write the chapter on Mysql tomorrow (may take a few hours to write... SOOOO complicated, in some areas of mysql...)
Mushroom5698
Reading this guide, it is assumed that you know absoutely NOTHING about php scripting...
Table of Contents:
Chapter 1. How to run a PHP script...
Chapter 2. The most basic of PHP scripting...
Chapter 3. Randomize...
Chapter 4. If/elseif/else commands... Allows your script to check stuff...
Chapter 5. The harder stuff... MYSQL! (full tutorial on EVERYTHING mysql
Chapter 6. Ill think of what I want for chapter 6, later, and when I do, ill post it.
Chapter 1 - How to run a PHP script...
Ok, if you are totally clueless on what a PHP script is, does, and how to use it, read this...
A PHP script IS a server side scripting language... In english, this meens that the person viewing the website won't get to see whats happening, unless you allow a way for them to see it...
A PHP script DOES just about anything you want it too...
To use a PHP script you must have a website... This website must have PHP enabled on it. If you are not sure if your website has php enabled, contact your provider... To use it you must upload a .php file to the server, and than run it in your browser.
Any questions? If so, please email me at Mushroom5698@aol.com and ill reply... If not, move on...
Chapter 2 - The most basic of PHP scripting...
This is the MOST BASIC script you could ever make... Ill go over it step by step in just a few seconeds...
<?php
echo("Hello, World!");
?>
On your computer, goto start, run, and type notepad. Copy and paste this code in notepad. Save the file as "hi.php" (include the quotes!). Upload this file to your website, and view it in your browser... Do you get what it does? If not, this is how it works...
<?php - This starts your PHP script... EVERY php script you make, will begin with this...
echo("Hello, World"); - this prints "Hello, World" in the browser
?> - This ends your PHP script... EVERY php script you make, will end with this...
Get it? If not please email me at Mushroom5698@aol.com, and I will help you with what ever you don't understand... If you understand it, go on...
Another basic thing in a PHP script you should know, is making notes... Here is a PHP script...
<?php
//This is a note
?>
What does this script do? Nothing... But, lets say you write a PHP script, and your not sure if you'll remember what everything does... Just put notes everywhere in the script, about what the next line does...
So, that is very basic stuff, yet, if you do not get it, send me an email!
Chapter 3 - Randomize!
Ok, it seems like there are SOOOO many people who want to know how to randomize stuff! Well, heres a very simple way...
Firstly, let me introduce arrays. Arrays, are just more than one value assigned to one variable... OH! I forgot to tell you how to make variables...
Ok, lets say you wanted to make a variable...
$hi = "hello";
Simple, right? That meens that whenever you typed $hi it would return hello... An example...
<?php
$hi = "hello, world";
echo "This is an example of a variable: $hi";
?>
Would print on the screen: This is an example of a variable: hello, world
Get it? If not email me!
Now, back to arrays... Lets say you wanted to store a list of colors, in one variable... You have to make an array, useing the FUNCTION array...
$colors = array("black","blue","green","red","yellow");
So, whenever you reference to $colors[0] you would get black... $colors[1] would be blue, $colors[2] would be green, and so on...
So, lets say we wanted to get a random color, and print it to the screen...
First we have to learn something new! The funcion array_rand
array_rand
Here is a sample code for it...
array_rand($colors, 1);
The $colors part tells it that the array were dealing with is called "colors"... The part the say 1, is telling it to pick out ONE random choice... This function will only return a number, however... We have to put that number in the array... At this point, it gets a little more complicated, but ill explain it to the best of my ability...
<?php
// Create an array stored in the variable called "colors"
$colors = array("black","blue","yellow","white");
// Get 1 random part of the array... (this will return 0 1 2 or 3)
$random_number = array_rand($colors,1);
// This is where it gets a little tricky... You remember how I said that if you
// Wanted to reference the "blue" in this array, you would have to reference
// $colors[1]..? Well, with this random thing its the same... Only, instead of
// saying one, we will reference $colors[$random_number]
// and store it in a variable called $result
$result = $colors[$random_number];
echo $result
?>
Thats all 4 this chapter... If you have any questions, email me at Mushroom5698@aol.com... Ill answer them all to the best of my ability...
Ill write the chapter on Mysql tomorrow (may take a few hours to write... SOOOO complicated, in some areas of mysql...)
Mushroom5698