我需要一个搜索查询。 年龄值10 - 15,20 - 25,17 - 19,12 - 59,2 - 19,18 - 40,10 - 20
我发送10 - 25,我希望通过匹配数字来获得结果
<?php
$Age1 = 10;
$Age2 = 25;
$Age = $Age1." - ".$Age2;
$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age LIKE '%" . $Age . "%'");
?>
感谢All
答案 0 :(得分:2)
您应该使用BETWEEN运算符,它选择给定范围内的值。
示例:
$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age BETWEEN 10 AND 25");
答案 1 :(得分:1)
我想你需要的是运营商之间。 Between运算符旨在选择给定范围内的值。在您的方案中,年龄范围。该运营商具有包容性。这意味着包含开始值和结束值。
<?php
$Age1 = 10;
$Age2 = 25;
$stmt = mysqli_query(
$con,
"SELECT * " .
"FROM job_post_p1 " .
"WHERE Age BETWEEN $Age1 AND $Age2"
);
答案 2 :(得分:-1)
$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age BETWEEN 10 AND 25");