The WHERE clause is used to filter records, which is to query the data under our specified conditions
## Type | Detailed explanation |
Basic syntax | select field from table where where condition; |
Example | select * from money where age = 29; |
Example description | Query all results with age 29 in the MyGuests table |
Let us use the following example:
Example
The following example will select all FirstNames from the "MyGuests" table ='Mary' row:
<?php
header("Content-type:text/html;charset=utf-8"); //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";
$con=mysqli_connect($servername, $username, $password, $dbname);
// 检测连接
if (mysqli_connect_errno())
{
echo "连接失败: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM MyGuests
WHERE FirstName='Mary'");
while($row = mysqli_fetch_array($result))
{
echo $row['firstname'] . "----" . $row['lastname'] ."----".$row['email'];
echo "<br>";
}
?>
Program execution result:

Use where condition to query all the data of FirstName='Mary' come out.
We now use phpadmin to add an Age field to the MyGuests table
The data in the table now looks like this:

Example
We now use the where clause to query those with Age less than 25:
<?php
header("Content-type:text/html;charset=utf-8"); //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";
$con=mysqli_connect($servername, $username, $password, $dbname);
// 检测连接
if (mysqli_connect_errno())
{
echo "连接失败: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM MyGuests
WHERE Age<25 ");
while($row = mysqli_fetch_array($result))
{
echo $row['firstname'] . "----" . $row['lastname'] ."----".$row['email']."----".$row['Age'];
echo "<br>";
}
?>
Program running results:

You can also use the following conditions
Symbol | Description |
## > | is greater than |
< | Less than |
## >= Greater than or equal to | |
<= Less than or equal to | |
## != | Not equal to |
! = | Equal to |
Logical operators
## Symbol | Description | ## or
Or | | and
And | |
Let’s take a look at an example of multiple conditions:
Example We query the data of 'firstname'='Julie' and Age=24
<?php
header("Content-type:text/html;charset=utf-8"); //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";
$con=mysqli_connect($servername, $username, $password, $dbname);
// 检测连接
if (mysqli_connect_errno())
{
echo "连接失败: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM MyGuests
WHERE Firstname='Julie' AND Age=24 ");
while($row = mysqli_fetch_array($result))
{
echo $row['firstname'] . "----" . $row['lastname'] ."----".$row['email']."----".$row['Age'];
echo "<br>";
}
?>
Program running results:Next Section<?php
header("Content-type:text/html;charset=utf-8"); //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";
$con=mysqli_connect($servername, $username, $password, $dbname);
// 检测连接
if (mysqli_connect_errno())
{
echo "连接失败: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM MyGuests
WHERE FirstName='Mary'");
while($row = mysqli_fetch_array($result))
{
echo $row['firstname'] . "----" . $row['lastname'] ."----".$row['email'];
echo "<br>";
}
?>
cp是什么单位hcv7jop7ns1r.cn |
鞭长莫及什么意思hcv7jop9ns4r.cn |
梦见换房子是什么预兆hcv7jop5ns5r.cn |
大舌头是什么意思hcv9jop2ns0r.cn |
脚水肿吃什么药youbangsi.com |
rover是什么意思hcv8jop8ns0r.cn |
98年的虎是什么命wmyky.com |
什么牌子的益生菌最好hcv9jop3ns9r.cn |
石光荣是什么军衔beikeqingting.com |
孕妇快生了有什么症状hcv8jop0ns3r.cn |
真菌怕什么hcv8jop9ns6r.cn |
渣男之首是什么星座jasonfriends.com |
冠状沟溃疡是什么病hcv8jop2ns0r.cn |
肚脐左侧疼是什么原因hcv9jop2ns3r.cn |
泞字五行属什么jinxinzhichuang.com |
紫苏有什么作用与功效dajiketang.com |
牙龈出血缺什么维生素hcv9jop6ns7r.cn |
五什么四什么hcv8jop7ns3r.cn |
梦到公鸡是什么意思hcv8jop6ns0r.cn |
道心是什么意思xinmaowt.com |
百度