Wednesday, August 10, 2011

PHP MySQL Select

The SELECT statement is used to select data from a database.


Select Data From a Database Table

The SELECT statement is used to select data from a database.

Syntax

SELECT column_name(s)
FROM table_name

To learn more about SQL, please visit our SQL tutorial.

To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.

Example

The following example selects all the data stored in the "Persons" table (The * character selects all the data in the table):

"
<
tr>
";

while($row = mysql_fetch_array($result))
{
echo "";
echo "";
echo "";
echo "";
}
echo "

Firstname Lastname
" . $row['FirstName'] . "" . $row['LastName'] . "
";

mysql_close($con);
?>

The output of the code above will be:

FirstnameLastname
GlennQuagmire
PeterGriffin

No comments:

Post a Comment