New Functions
printf()
printf() is basically the same as print(), only it gives you a little more precision as to how you want to format the display of your variables. In the following example, the %s is replaced by the variables at the end of the statement. The %s tells the printf function to format the variables as strings, as opposed to, say, an integer or binary number.
printf("<TR><TD>%s</TD><TD>%s</TD></TR>\n", $row["col1"], $row["col2"]);
while
The while statement is a simple looping mechanism that allows you to evaluate a set of data until it comes across a value that doesn't meet the required criteria. The loop is exited once the evaluation against the criteria is proven false. This function is useful if you don't know the size of the data set you need to evaluatefor instance, some data retrieved from a database.
while($a == $b) { print("<P> $a is equal to $b \n"); }
mysql_connect
The mysql_connect function establishes a connection with a MySQL Server. It takes as its arguments the MySQL server location, your MySQL login, and your MySQL password.
This function is usually assigned to a variable that is then used in the mysql_select_db function.
$server_connection = mysql_connect("localhost", "chris", "password1");
NOTE
The password argument is necessary only if you have set a MySQL password for yourself. If you don't have a password, and don't need one to connect to the server, you can leave the password argument out of the function.
mysql_select_db
The mysql_select_db function selects a particular MySQL database on a MySQL server. It takes as its arguments the database name and the MySQL server connection. You must use this function to select a database on the server before you can send queries.
mysql_select_db("news", "$server_connection");
mysql_query
The mysql_query function sends SQL queries to a database on a MySQL server. It takes as its argument an SQL query. If you are connecting to more than one MySQL server in a script, then you can specify which connection you want to query by adding a server connection to the arguments.
$result = mysql_query("SELECT * FROM news"); $result = mysql_query("SELECT * FROM news", "$server_connection");
mysql_fetch_array
The mysql_fetch_array function takes the first row of the result of a MySQL query and puts it into an array. Each call to this function gets the next row of the data from the result of the query until no rows are left. Either the column number or the column name can reference the array.
$myrow = mysql_fetch_array($result);