MySQL Where

The WHERE clause is used for extracting only those records that fulfill a specified criterion. If you wanted to select only certain entries of your table, then you would use the keyword WHERE. WHERE lets you specify requirements that entries must meet in order to be returned in the MySQL result. Those entries that do not pass the test will be left out.
Syntax:
1
2
3
4
5
SELECT column_name(s)
 
FROM table_name
 
WHERE column_name operator value
To get PHP to execute the statement above you must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.
The following example selects all rows from the Persons table where FirstName='Peter':
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("my_db", $con);
 
$result = mysql_query("SELECT * FROM Persons
WHERE FirstName='Peter'");
 
while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }
?>
MySQL Insert
MySQL Select
MySQL Order By
MySQL Update