带有下拉字段的搜索栏的搜索查询是什么
我必须从db中获取结果,该数据库有2个表
1. content_ref_table与字段
标题,描述,网址,course_id
我必须在与所选课程相对应的标题和说明字段中搜索输入的文本
HTML
<input id ="search_bar" name= "search_bar"type="text" class="form-control" placeholder="Search" >
<span class="input-group-addon">
<select class="form-control" name="selectVal">
<option value="course">Select Course</option>
<?php
$sql = mysqli_query($conn,"call courses_dropdown()");
while($row = mysqli_fetch_array($sql))
{
echo "<option value='" . $row['courses'] ."'>" . $row['courses'] . "</option>";
}
?>
</select>
</span>
<span class="input-group-addon">
<button type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</form>
php
<?php
include 'includes/dbconfig.php';
$search_term = $_GET['search_bar'];
$select_course = $_GET['select_course'];
$query = mysqli_query($conn,"SELECT * FROM content_ref_table WHERE title LIKE '%".$search_term."%' OR description LIKE '%".$search_term."%' LIMIT 0 , 30")
?>
答案 0 :(得分:0)
在我看来,您的查询应该是这样的:
$query = mysqli_query($conn,"SELECT * FROM content_ref_table,course_ref_table
WHERE title LIKE '%".$search_term."%' OR description LIKE '%".$search_term."%'
and content_ref_table.course_id = course_ref_table.course_id
and courses = '".$selected_course."' LIMIT 0 , 30")