我有一个表,包括id,标题和文本。从下拉菜单中,我让用户选择标题和文本。基于标题和文本,我想显示搜索结果。但是当我使用 AND
运算符它不显示任何结果,尽管匹配的数据在数据库中可用。有人能帮我弄清楚吗?
这是查询搜索代码
$search_value=$_POST["search"];
$services=$_POST["services"];
$sql="select * from articles where title like '%$search_value%' AND text like '%services%' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["title"]. $row["text"];
}
} else {
echo "0 results";
}
这是下拉列表
<form action="search.php" method="post">
<select class="form-control" name="search" id="select1">
<option value="Ampara">Ampara</option>
<option value="Anuradhapura">Anuradhapura</option>
<option value="Badulla">Badulla</option>
<option value="Batticaloa">Batticaloa</option>
<option value="Colombo">Colombo</option>
</select>
<select class="form-control" name="services" >
<option value="Architecture">Architecture</option>
<option value="Astrology">Astrology</option>
<option value="Electrical">Electrical</option>
<option value="Landscaping">Landscaping</option>
<option value="Hardware">Hardware</option>
<option value="Plumbing">Plumbing</option>
</select>
这是我的数据库表的截图
1条答案
按热度按时间owfi6suc1#
请用以下内容替换您的查询,查询中缺少文本字段的$sign-in services变量