The best PHP MySQL Where Clause Tutorial In 2024, In this tutorial you can learn WHERE clause,
WHERE clause is used to filter the records.
WHERE clause is used to extract records that meet the specified criteria.
SELECT column_name(s) FROM table_name WHERE column_name operator value
To learn more about SQL knowledge, please visit our SQL tutorial .
To get PHP to execute the statement above we must use mysqli_query () function. This function is used to send a query or command MySQL connection.
The following "Persons" table, select instances from all FirstName = 'Peter' line:
<?php $con=mysqli_connect("localhost","username","password","database"); // 检测连接 if (mysqli_connect_errno()) { echo "连接失败: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM Persons WHERE FirstName='Peter'"); while($row = mysqli_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br>"; } ?>
The code above will output:
Peter Griffin