www.pickatutorial.com Computer Tutorials

PHP MySQL SELECT Statement. Free online PHP and MySQL Web Database Programming Tutorial...

Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script
Lessons MySQL SELECT Statement Bookmark and Share
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
We use the SELECT statement to select or retrieve data from a database. Its systax follows:

SELECT column_name(s)
FROM table_name


We have to use PHP mysql_query() function to execute the above statement. Let's see an example:

Example
The following example selects all the data stored in the "Students" table. Note that the * character is used to select all the data in the table:

<?php
$con = mysql_connect("localhost", "adam", "ada");
if (!$con)
{
die('Error connecting database');
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Students ");
while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['address'];
echo "<br />";
}
mysql_close($con);
?>

The above example stores the data returned by the mysql_query() function in the $result variable. It, then uses the mysql_fetch_array() function in the while loop to display that data. Please note that the first call to mysql_fetch_array() returns the first record, second call to the function returns the second record and so on. To print the value of each row, we use the PHP $row variable ($row['name'] and $row['address']).


Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.