【发布时间】:2013-02-19 22:29:54
【问题描述】:
在我的网站中,我有一个页面来显示推荐。我编写了这段代码来显示我在数据库中的所有推荐。
这是我目前的代码:
while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC)) {
$testimonial = $row['testimonial'];
//echo $testimonial;
$mytestimonial = nl2br($testimonial);
$city = $row['city_name'];
$name = $row['name'];
$url = $row['web_address'];
$imageName = $row['image_name'];
$type = $row['membership_type'];
}
使用此代码,我可以将我的所有推荐信带到该页面。它很适合我。我的问题是现在我需要根据其类型过滤我的推荐。我的数据库中有 3 种不同类型的推荐信。 (导师,学院,学生)
我将使用一个选择框来过滤数据。从选择框中选择一个选项时,我需要根据所选类型显示推荐。
<div class="filter-box">
<div id="select_box">
<form method="post" action="">
<div class="variation2">
<label>Filter By</label>
<select class="select">
<option>Tutor</option>
<option>Institute</option>
<option>Student</option>
</select>
</div>
</form>
</div>
</div>
谁能帮我找到一个方向?
谢谢
【问题讨论】:
-
在查询中插入
where子句。我也建议使用 Ajax。 -
1.为您的选择框命名 2. 接受此值作为类型 3. 使用此类型变量在查询中进行过滤 -- “SELECT testimonial, city_name, name, web_address, image_name, member_type FROM testimonials INNER JOIN city ON city.city_id = testimonials.city_id where type = $type ORDER BY date_added DESC LIMIT $start, $display";"