Posted By

Masis on 06/11/10


mysql where

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


MySQL Where

 / Published in: MySQL


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. 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. <?php
  2. $con = mysql_connect("localhost","peter","abc123");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  8. mysql_select_db("my_db", $con);
  10. $result = mysql_query("SELECT * FROM Persons
  11. WHERE FirstName='Peter'");
  13. while($row = mysql_fetch_array($result))
  14. {
  15. echo $row['FirstName'] . " " . $row['LastName'];
  16. echo "<br />";
  17. }
  18. ?>

Report this snippet  

You need to login to post a comment.