MySQL Select Statement with Where clause in PHP code

Submitted by:Jhon Brain

Date added:22 October, 2011

Category:MySQL

If we wanted to select only certain entries of our table, then we would use the WHERE clause .

Tags: mysql code

Code Snippet:

<?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM example
WHERE name='Sandy Smith'") or die(mysql_error());

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table
echo $row['name']." - ".$row['age'];
?>
 
 

Comments