PHP/MySQL Tutorial Part 4 – Retrieve Data
To retrieve after inserting them (see older post PHP/MySQL Tutorial Part 3), simply select the record from the desired table. Use this SQL statement:
SELECT * FROM table_name;
Eg.
$result = mysql_query(“SELECT * FROM tablename”);
$row = mysql_fetch_assoc($result);
while($row = mysql_fetch_assoc($result))
{
echo $row['name'];
echo “-”;
echo $row['email'];
}
This would display:
Terence – terence@someemail.com
Johnny – johnny@otheremail.com
You can control the results with varying the statement. Eg.
SELECT name FROM tablename – retreives the name column only
SELECT * FROM tablename ORDER BY id DESC – shows last record first
SELECT * FROM tablename LIMIT 5 – shows the first 5 results only
Tags: PHP MySQL, php mysql tutorial, php retreive mysql
This entry was posted on Sunday, February 15th, 2009 at 2:20 am and is filed under PHP MySQL. You can follow any responses to this entry through the RSS 2.0 feed. Responses are currently closed, but you can trackback from your own site.







