我一直在使用此代碼在我的網站上顯示一些推薦。自動提交表單和MYSQL詢問
這是到目前爲止的代碼:
// Select testimonials from database
$q = "SELECT testimonial, city_name, name, web_address, image_name, membership_type
FROM testimonials
INNER JOIN city ON city.city_id = testimonials.city_id
ORDER BY date_added DESC LIMIT $start, $display";
$r = mysqli_query($dbc, $q);
if ($records >= 1) {
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'];
echo '<div class="testimonial-row">
<div class="testimonial-image">
<img src="'.UPLOAD_DIR.$imageName.'" />
</div>
<div class="testimonial">
<h2>'.$name.'</h2>
<h3>';
if($type==1){
echo 'A teacher';
}elseif($type==2){
echo 'An Institute';
}elseif($type==3){
echo 'A Student';
}
echo " from <strong>$city</strong></h3>
<blockquote>$mytestimonial</blockquote>
<p class='user-url'><a href=''>$url</a></p>
</div>
</div>";
}
} else {
echo "There is no any testimonial to display at this time. Please try again later.";
}
上面的代碼,我可以展示我的全部證明後運行。我有3種不同的推薦,目前在我的頁面中顯示所有種類的推薦。
現在我要選擇一個解決方案來根據其類型篩選和顯示它們。
這是我的選擇框:
<select class="select" name="type">
<option value="1">Tutor</option>
<option value="2">Institute</option>
<option value="3">Student</option>
</select>
當選擇從選擇框,我過濾應requering我原來的查詢與選擇的類型發生的選項。我有一個解決方案與jQuery的顯示/隱藏功能,但它不符合預期的結果。
注:我不能使用提交按鈕與此選擇框。這就是爲什麼我正在尋找Ajax或Jquery的解決方案。
任何人都可以告訴我是否有可能嗎?
謝謝。
肯定可以....在選擇框的變化情況.. AJAX調用,將篩選結果... – alwaysLearn 2013-03-15 12:04:26
我可以知道我該怎麼做?我試着用jquery,但無法讓它工作。 – TNK 2013-03-15 12:06:16
可能會幫你 http://stackoverflow.com/questions/14603807/php-mssql-filtering-from-user-input-html/14604096#14604096 – Samy 2013-03-15 12:07:31