1 pertemuan 13 php-mysql last updated: 15 th may 2010 by m. arief

50
1 Pertemuan 13 Pertemuan 13 PHP-MySQL PHP-MySQL Last Updated: 15 th May 2010 By M. Arief http://arief.ismy.web.id

Upload: may-oneal

Post on 26-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

11

Pertemuan 13Pertemuan 13

PHP-MySQLPHP-MySQLLast Updated: 15th May 2010

By M. Ariefhttp://arief.ismy.web.id

2

ObjectivesObjectives►To understand what PHP is and how a PHP To understand what PHP is and how a PHP

script works with a Web Browser and a script works with a Web Browser and a Web ServerWeb Server

►To create and run a simple PHP script To To create and run a simple PHP script To learn how to store and access data in PHP learn how to store and access data in PHP variablesvariables

►To understand the advantages of using To understand the advantages of using databases in Web applicationsdatabases in Web applications

►To learn how to prepare a MySQL database To learn how to prepare a MySQL database for use with PHPfor use with PHP

►To learn how to store, retrieve, and update To learn how to store, retrieve, and update data in a MySQL databasedata in a MySQL database

http://arief.ismy.web.id

3

ReferencesReferences

►http://www.php.nethttp://www.php.net►http://www.mysql.orghttp://www.mysql.org►http://www.apache.orghttp://www.apache.org

http://arief.ismy.web.id

4

PHP HistoryPHP History► PHP originally stood for Personal Home PagesPHP originally stood for Personal Home Pages► PHP is now a recursive acronym that stands PHP is now a recursive acronym that stands

for Hypertext Preprocessorfor Hypertext Preprocessor► Rasmus Lerdorf created Personal Homepage Rasmus Lerdorf created Personal Homepage

Tools/Form Interpreter in 1995.Tools/Form Interpreter in 1995.► In 1997 PHP/FI was rewritten: 50,000 domains In 1997 PHP/FI was rewritten: 50,000 domains

were using it.were using it.► In 1998, college students Andi Gutmans and In 1998, college students Andi Gutmans and

Zeev Suraski rewrote it, released v3 and Zeev Suraski rewrote it, released v3 and renamed it PHP:renamed it PHP:

► Hypertext Preprocessor. Over 1 million Hypertext Preprocessor. Over 1 million domains.domains.

► Late 1998, Zeev and Andi rewrote it again, and Late 1998, Zeev and Andi rewrote it again, and called it v4; Developed the Zend Engine which called it v4; Developed the Zend Engine which precompiled code. ~20 million domains today.precompiled code. ~20 million domains today.

http://arief.ismy.web.id

5

PHP HistoryPHP History► Some of PHP’s main competitors are Some of PHP’s main competitors are

Perl, ASP, JSP and ColdFusionPerl, ASP, JSP and ColdFusion► PHP has many strengths that include:PHP has many strengths that include:

High performanceHigh performance Interface to many different database Interface to many different database

systemssystems Build-in libraries for many common web Build-in libraries for many common web

taskstasks It is freeIt is free Ease of learning and useEase of learning and use Strong object-oriented supportStrong object-oriented support PortabilityPortability Availability of source codeAvailability of source code Availability of supportAvailability of support

http://arief.ismy.web.id

6

PHP HistoryPHP History

http://arief.ismy.web.id

7

Server Side ScriptingServer Side Scripting

►Not a Client Side Scripting (JavaScript, VBScript)

►Main scripting languages PHP (PHP: Hypertext Preprocessor) JSP (Java Server Pages) ASP.NET (Active Server Pages) ColdFusion Perl

http://arief.ismy.web.id

8

PHP is C or Java StylePHP is C or Java Style

►PHP is based on C and Perl.►As a consequence if you know C,

Perl, C++ or java (also a C++ clone), or indeed almost any other computer science language you pretty much already know PHP.

http://arief.ismy.web.id

9

PHP Tag StylePHP Tag Style► XML Style:► <?php

PHP Code In Herephp?>

► Short Style:► <?

PHP Code In Here?>

► Script Style:► <script language="php">

PHP Code In Here</script>

http://arief.ismy.web.id

10

Embedding PHP in HTMLEmbedding PHP in HTML

<HTML><HEAD><TITLE>Search results for "<?php

print $query;?>"</TITLE></HEAD><BODY>

http://arief.ismy.web.id

11

PHP Statement and Ending LinesPHP Statement and Ending Lines

►• A statement in PHP is an executable line of code, which generally consist of a function and an argument.

►• Notice that the PHP statement in the past example is terminated with a semi-colon ‘;’

►• All statements in PHP are terminated with ;

http://arief.ismy.web.id

12

Switching ModesSwitching Modes<?

if( …….. ){

?><b>You are using PHP</b>

<?}else{

?> <b>You are not using PHP</b>

<?}

?>

http://arief.ismy.web.id

13

CommentsComments►Why do we concern ourselves with

comments so much?►• because without them,

understanding scripts would be difficult.

<? //C style comment/* C multi line comment*/

?>http://arief.ismy.web.id

14

PHP TypesPHP Types► Basic data types► – Integer - Used for whole numbers► – Float (also double) - Used for real numbers► – String - Used for strings of characters► – Boolean – Used for true or false values► – Array - Used to store multiple data items► – Object - Used for storing instances of classes

► Dynamic typing► – Don't have to declare types► – Automatic conversion done► – Supports typecasting eg. $total = (float) $sum;► – Variable variables eg $$varname = 5;

http://arief.ismy.web.id

15

Variables in PHPVariables in PHP<?

$x = false; // boolean$x = true;$x = 10; // decimal$x = 1.45; // Floating point$x = 0x1A; // hexadecimal$x = "PHP's site \n"; // PHP’s site and a new line$x[1] = 10 // array of decimals$x[2]["num"] = "xx"; // a two dimensional array

?>

Type Casting<?

$bool = true;print (int)$bool; // 1

?>

http://arief.ismy.web.id

16

Output to BrowserOutput to Browser

Several different ways:►print(); is a function that will print the

contents of an argument to the screen. Ex. print ("Here is an argument."); Ex. Print ("<p>It can be anything.</p>");

►Echo is not a function; it is a language construct, so doesn’t need parentheses. Ex. echo "<p>It can be a single

word.</p>";http://arief.ismy.web.id

17

Predefined VariablesPredefined Variables

► PHP has a number of predefined variables.► Predefined variables are always capitalized.► $GLOBALS contains names and values of

all predefined variables.► Create a PHP file called predefined.php and

insert:<?phpecho "<pre>";print_r ($GLOBALS);echo "</pre>";?>

► Save it then view in browser.http://arief.ismy.web.id

18

Global VariablesGlobal Variables

►Storing form data in simple variables is a major security risk, as users can easily guess variable names by looking at forms.

►We have register_globals turned off, as do most security minded hosting companies.

►So, form variables and data are stored in global variables $_POST or $_GET, based on your form method. Ex. <input type="text" name="email">

isavailable as $_POST['email']; or $_GET['email'];

http://arief.ismy.web.id

19

ConstantsConstants

►A constant is a special data type in PHP►Unlike a variable they maintain their

value throughout the life of a script.►Since constants aren't variables, they do

not begin with a $.►Cannot be changed once set.

Good for values you don't want to inadvertently change by mixing up = with ==.

► Rule of thumb is to name constants in ALLCAPS.

http://arief.ismy.web.id

20

ConstantsConstants

►Use define(); function to create a constant: define('FIRSTNAME', ‘John');

►Constants don't expand within quotes as variables do. echo "Hello FIRSTNAME"; //prints

"Hello FIRSTNAME" echo "Hello“ .FIRSTNAME; //prints

“Hello John”

http://arief.ismy.web.id

21

Check if a Constant is DefinedCheck if a Constant is Defined

►Use the defined() function to check if a constant is defined defined('CONSTANT_NAME') Returns true if constant is defined Example:

if (defined('FIRSTNAME')){

echo 'Welcome' .FIRSTNAME . '!';

} else {

echo 'You must give your name.';

}

http://arief.ismy.web.id

22

PHP OperatorsPHP Operators

+ Addition- Subtraction* Multiplication/ Division% Modulus& And| OR^ Xor. add string (concatenate)

http://arief.ismy.web.id

23

Numerical FunctionNumerical Function

Addition $a = 1 + 1; // sets $a to 2 $a+= 4; // adds 4 to $a $a++; // adds 1 to $a

Subtraction $a = 10 - 5; # sets $a to 5 $a -= 6; # subtracts 6 from $a $a--; # subtracts 1 from

$ahttp://arief.ismy.web.id

24

Numerical FunctionNumerical Function

Multiplication $a = 2 * 3; // sets $a to 6 $a *= 10; // multiplies $a by 10

Division $a = 10 / 3; // sets $a to 3.3333 $a /= 2; // halves $a

Modulus $a = 10 % 3; // sets $a to 1 $a %= 2; // sets $a to modulus 2 of

itself

http://arief.ismy.web.id

25

PHP InfoPHP Info► Type your Code, save as info.php

<html><head><title>Exercise 1</title></head><body>

This is the plain HTML text<br /><br />

<?phpphpinfo();?>

</body></html>

► Upload in a webserver C:\xampp\htdocs\YourName

► View from Browser http://localhost/NamaAnda/info.php

http://arief.ismy.web.id

2626

Pertemuan 13Pertemuan 13

MySQLMySQLLast Updated: 15th May 2010

By M. Arief

http://arief.ismy.web.id

27

ObjectivesObjectives►To learn how to prepare a MySQL To learn how to prepare a MySQL

database for use with PHPdatabase for use with PHP►To learn how to store, retrieve, To learn how to store, retrieve,

and update data in a MySQL and update data in a MySQL databasedatabase

http://arief.ismy.web.id

28

Which Database Systems?Which Database Systems?►PHP works with a variety of

databases that include: Oracle SQL Server Access Ingres MySQL

►We will use MySQL since it is simple to use, free and very popular.

http://arief.ismy.web.id

29

PHP-MySQLPHP-MySQL

http://arief.ismy.web.id

30

PHP-MySQLPHP-MySQL►Within MySQL, use Structured

Query Language (SQL), to access database

►Embed SQL within PHP scripts and use predefined function

http://arief.ismy.web.id

31

mysql_connect() and mysql_close()mysql_connect() and mysql_close()

►mysql_connect() establishes a connection to a MySQL server.

►It takes 3 parameters. The address of the server The username for that db account The password

►$conn = mysql_connect("195.251.218.103", "user", "pass");

►mysql_close() closes the connection to the database server.

http://arief.ismy.web.id

32

mysql_select_db()mysql_select_db()

►mysql_select_db() selects a specific database so any queries you make are against this database.

mysql_select_db("dbname",$conn);

http://arief.ismy.web.id

33

mysql_query()mysql_query()

►mysql_query() executes a specific query using the database connection identifier.

►It sends a line of SQL to the MySQL server to be processed.

►This is the key command for interacting with the database.

►In our example the results that are returned are stored in the variable $result.

http://arief.ismy.web.id

34

35

mysql_result()mysql_result()

►mysql_result() is used to traverse the result set returned from a query:

mysql_result($result,0,"first");

►Go to the first row of the result set $result, which is numbered 0, and return the value of the specified fields “first”.

http://arief.ismy.web.id

36

37

Example: The Contacts Example: The Contacts DatabaseDatabase

Name Name Type Type Length Length DescriptionDescriptionidid INTINT 66 A unique identifier for each A unique identifier for each

recordrecordfirstfirst VARCHARVARCHAR 1515 The person's first nameThe person's first namelastlast VARCHARVARCHAR 1515 The person's last nameThe person's last namephonephone VARCHARVARCHAR 2020 The person's phone numberThe person's phone numberMobileMobile VARCHARVARCHAR 2020 The person's mobile numberThe person's mobile numberfaxfax VARCHARVARCHAR 2020 The person's fax The person's fax

numbernumberemailemail VARCHARVARCHAR 3030 The person's e-mail addressThe person's e-mail addresswebweb VARCHARVARCHAR 3030 The person's web addressThe person's web address

38

Create The Contacts Database: Create The Contacts Database: setup.phpsetup.php

<?<?$user="username";$user="username";$password="password";$password="password";$database="database";$database="database";mysql_connect(localhost,$user,$password);mysql_connect(localhost,$user,$password);@mysql_select_db($database) or die( "Unable to select @mysql_select_db($database) or die( "Unable to select

database");database");$query="CREATE TABLE contacts ($query="CREATE TABLE contacts (

id int(6) NOT NULL auto_increment,id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,first varchar(15) NOT NULL,last varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 PRIMARY KEY (id),UNIQUE id (id),KEY id_2

(id))";(id))";mysql_query($query);mysql_query($query);mysql_close();mysql_close();?>?>

39

Insert Data: Form add.htmlInsert Data: Form add.html

<form action="insert.php" method="post"><form action="insert.php" method="post">First Name: <input type="text" name="first"><br>First Name: <input type="text" name="first"><br>Last Name: <input type="text" name="last"><br>Last Name: <input type="text" name="last"><br>Phone: <input type="text" name="phone"><br>Phone: <input type="text" name="phone"><br>Mobile: <input type="text" name="mobile"><br>Mobile: <input type="text" name="mobile"><br>Fax: <input type="text" name="fax"><br>Fax: <input type="text" name="fax"><br>E-mail: <input type="text" name="email"><br>E-mail: <input type="text" name="email"><br>Web: <input type="text" name="web"><br>Web: <input type="text" name="web"><br><input type="Submit"><input type="Submit">

</form></form>

40

Insert Data: insert.phpInsert Data: insert.php<?<?$username="username";$username="username";$password="password";$password="password";$database="your_database";$database="your_database";

$first=$_POST['first'];$first=$_POST['first'];$last=$_POST['last'];$last=$_POST['last'];$phone=$_POST['phone'];$phone=$_POST['phone'];$mobile=$_POST['mobile'];$mobile=$_POST['mobile'];$fax=$_POST['fax'];$fax=$_POST['fax'];$email=$_POST['email'];$email=$_POST['email'];$web=$_POST['web'];$web=$_POST['web'];

mysql_connect(localhost,$username,$password);mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select @mysql_select_db($database) or die( "Unable to select

database");database");

$query = "INSERT INTO contacts VALUES $query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";('','$first','$last','$phone','$mobile','$fax','$email','$web')";

mysql_query($query);mysql_query($query);

mysql_close();mysql_close();?>?>

41

Output Data: output.phpOutput Data: output.php<?<?$username="username";$username="username";$password="password";$password="password";$database="your_database";$database="your_database";

mysql_connect(localhost,$username,$password);mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select @mysql_select_db($database) or die( "Unable to select

database");database");$query="SELECT * FROM contacts";$query="SELECT * FROM contacts";$result=mysql_query($query);$result=mysql_query($query);

$num=mysql_numrows($result);$num=mysql_numrows($result);

mysql_close();mysql_close();

42

Output Data: output.phpOutput Data: output.phpecho "<b><center>Database Output</center></b><br><br>";echo "<b><center>Database Output</center></b><br><br>";

$i=0;$i=0;while ($i < $num) {while ($i < $num) {

$first=mysql_result($result,$i,"first");$first=mysql_result($result,$i,"first");$last=mysql_result($result,$i,"last");$last=mysql_result($result,$i,"last");$phone=mysql_result($result,$i,"phone");$phone=mysql_result($result,$i,"phone");$mobile=mysql_result($result,$i,"mobile");$mobile=mysql_result($result,$i,"mobile");$fax=mysql_result($result,$i,"fax");$fax=mysql_result($result,$i,"fax");$email=mysql_result($result,$i,"email");$email=mysql_result($result,$i,"email");$web=mysql_result($result,$i,"web");$web=mysql_result($result,$i,"web");

echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";$web<br><hr><br>";

$i++;$i++;}}

?>?>

43

Output Data: table format, Output Data: table format, outputtable.phpoutputtable.php<table border="0" cellspacing="2" cellpadding="2"><table border="0" cellspacing="2" cellpadding="2">

<tr><tr><th><font face="Arial, Helvetica, sans-serif">Name</font></th><th><font face="Arial, Helvetica, sans-serif">Name</font></th><th><font face="Arial, Helvetica, sans-serif">Phone</font></th><th><font face="Arial, Helvetica, sans-serif">Phone</font></th><th><font face="Arial, Helvetica, sans-serif">Mobile</font></th><th><font face="Arial, Helvetica, sans-serif">Mobile</font></th><th><font face="Arial, Helvetica, sans-serif">Fax</font></th><th><font face="Arial, Helvetica, sans-serif">Fax</font></th><th><font face="Arial, Helvetica, sans-serif">E-mail</font></th><th><font face="Arial, Helvetica, sans-serif">E-mail</font></th><th><font face="Arial, Helvetica, sans-serif">Website</font></th><th><font face="Arial, Helvetica, sans-serif">Website</font></th></tr></tr>

<?<?$i=0;$i=0;while ($i < $num) {while ($i < $num) {$first=mysql_result($result,$i,"first");$first=mysql_result($result,$i,"first");$last=mysql_result($result,$i,"last");$last=mysql_result($result,$i,"last");$phone=mysql_result($result,$i,"phone");$phone=mysql_result($result,$i,"phone");$mobile=mysql_result($result,$i,"mobile");$mobile=mysql_result($result,$i,"mobile");$fax=mysql_result($result,$i,"fax");$fax=mysql_result($result,$i,"fax");$email=mysql_result($result,$i,"email");$email=mysql_result($result,$i,"email");$web=mysql_result($result,$i,"web");$web=mysql_result($result,$i,"web");?>?>

44

Output Data: table formatOutput Data: table format<tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo $first." ".$last; ?<td><font face="Arial, Helvetica, sans-serif"><? echo $first." ".$last; ?

></font></td>></font></td><td><font face="Arial, Helvetica, sans-serif"><? echo $phone; <td><font face="Arial, Helvetica, sans-serif"><? echo $phone;

?></font></td>?></font></td><td><font face="Arial, Helvetica, sans-serif"><? echo $mobile; <td><font face="Arial, Helvetica, sans-serif"><? echo $mobile;

?></font></td>?></font></td><td><font face="Arial, Helvetica, sans-serif"><? echo $fax; <td><font face="Arial, Helvetica, sans-serif"><? echo $fax;

?></font></td>?></font></td><td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo

$email; ?>">E-mail</a></font></td>$email; ?>">E-mail</a></font></td><td><font face="Arial, Helvetica, sans-serif"><a href="<? echo $web; ?<td><font face="Arial, Helvetica, sans-serif"><a href="<? echo $web; ?

>">Website</a></font></td>>">Website</a></font></td></tr></tr>

<?<?$i++;$i++;}}

echo "</table>";echo "</table>";

45

Update DataUpdate Data$id=$_POST['id'];$id=$_POST['id'];

$username="username";$username="username";

$password="password";$password="password";

$database="your_database";$database="your_database";

mysql_connect(localhost,$username,$password);mysql_connect(localhost,$username,$password);

$query=" SELECT * FROM contacts WHERE id='$id'";$query=" SELECT * FROM contacts WHERE id='$id'";

$result=mysql_query($query);$result=mysql_query($query);

$num=mysql_numrows($result);$num=mysql_numrows($result);

mysql_close();mysql_close();

46

Update DataUpdate Data$i=0;$i=0;

while ($i < $num) {while ($i < $num) {

$first=mysql_result($result,$i,"first");$first=mysql_result($result,$i,"first");

$last=mysql_result($result,$i,"last");$last=mysql_result($result,$i,"last");

$phone=mysql_result($result,$i,"phone");$phone=mysql_result($result,$i,"phone");

$mobile=mysql_result($result,$i,"mobile");$mobile=mysql_result($result,$i,"mobile");

$fax=mysql_result($result,$i,"fax");$fax=mysql_result($result,$i,"fax");

$email=mysql_result($result,$i,"email");$email=mysql_result($result,$i,"email");

$web=mysql_result($result,$i,"web");$web=mysql_result($result,$i,"web");

Space For CodeSpace For Code

++$i;++$i;

}}

47

Update Data: Space for CodeUpdate Data: Space for Code

<form action="<form action="updated.phpupdated.php" method="post">" method="post">

<input type="<input type="hiddenhidden" name="ud_id" value="<? echo $id; ?>">" name="ud_id" value="<? echo $id; ?>">

First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>

Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>

Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?>"><br>>"><br>

Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?>"><br>>"><br>

Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>

E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>>"><br>

Web Address: <input type="text" name="ud_web" value="<? echo $web; ?Web Address: <input type="text" name="ud_web" value="<? echo $web; ?>"><br>>"><br>

<input type="Submit" value="Update"><input type="Submit" value="Update">

</form></form>

48

Update Data: updated.phpUpdate Data: updated.php$ud_id=$_POST['ud_id'];$ud_id=$_POST['ud_id'];

$ud_first=$_POST['ud_first'];$ud_first=$_POST['ud_first'];

$ud_last=$_POST['ud_last'];$ud_last=$_POST['ud_last'];

$ud_phone=$_POST['ud_phone'];$ud_phone=$_POST['ud_phone'];

$ud_mobile=$_POST['ud_mobile'];$ud_mobile=$_POST['ud_mobile'];

$ud_fax=$_POST['ud_fax'];$ud_fax=$_POST['ud_fax'];

$ud_email=$_POST['ud_email'];$ud_email=$_POST['ud_email'];

$ud_web=$_POST['ud_web'];$ud_web=$_POST['ud_web'];

$username="username";$username="username";

$password="password";$password="password";

$database="your_database";$database="your_database";

mysql_connect(localhost,$username,$password);mysql_connect(localhost,$username,$password);

$query="UPDATE contacts SET first='$ud_first', last='$ud_last', $query="UPDATE contacts SET first='$ud_first', last='$ud_last', phone='$ud_phone', mobile='$ud_mobile', fax='$ud_fax', email='$ud_email', phone='$ud_phone', mobile='$ud_mobile', fax='$ud_fax', email='$ud_email', web='$ud_web' WHERE id='$ud_id'";web='$ud_web' WHERE id='$ud_id'";

mysql_query($query);mysql_query($query);

echo "Record Updated";echo "Record Updated";

mysql_close();mysql_close();

49

OthersOthersSelecting Pieces of Data:Selecting Pieces of Data:► $query="SELECT * FROM contacts WHERE $query="SELECT * FROM contacts WHERE last='$searchlast'";last='$searchlast'";

► $result=mysql_query($query);$result=mysql_query($query);

Error Tapping:Error Tapping:► if ($num==0) {if ($num==0) {echo "The database contains no contacts yet";echo "The database contains no contacts yet";} else {} else {Output LoopOutput Loop} }

Ordering Data:Ordering Data:► SELECT * FROM contacts ORDER BY last ASC SELECT * FROM contacts ORDER BY last ASC

50

OthersOthersEfficiency:Efficiency:► dbinfo.inc.phpdbinfo.inc.php

► <?<?► $username="databaseusername";$username="databaseusername";► $password="databasepassword";$password="databasepassword";► $database="databasename";$database="databasename";► ?>?>

► include("dbinfo.inc.php");include("dbinfo.inc.php");