The WHERE clause is used to filter records.
The WHERE clause is used to extract records that meet specified criteria.
SELECT column_name(s)FROM table_nameWHERE column_name operator value
To learn more about SQL, visit our SQL tutorials.
In order for PHP to execute the above statement, we must use the mysqli_query() function. This function is used to send queries or commands to the MySQL connection.
The following example will select all rows from the "Persons" table with FirstName='Peter':
<?php$con=mysqli_connect("localhost","username","password","database");//Detect connection if (mysqli_connect_errno()){ echo "Connection failed: " . mysqli_connect_error();}$result = mysqli_query($con,"SELECT * FROM PersonsWHERE FirstName='Peter'");while($row = mysqli_fetch_array($result)){ echo $row['FirstName'] . " " . $row['LastName']; echo "<br>";}?>
The above code will output:
Peter Griffin