我希望用戶能夠篩選具有多個類別選擇的項目。 目前,用戶可以從下拉列表中選擇一個類別,並僅查看該類別的項目。我想要做的是,在添加更多下拉菜單後,點擊「添加更多」按鈕,讓用戶選擇更多類別帶多個類別篩選的PHP'添加更多'鏈接
不確定如何爲每個類別添加唯一的ID。任何幫助表示讚賞!
<script>
function addInput(divName, template){
var newdiv = document.createElement('div');
newdiv.innerHTML = document.getElementById(divName).innerHTML;
document.getElementById(template).appendChild(newdiv);
}
</script>
<div id="template">
<select name="category">
<?php
$res = mysql_query("SELECT * FROM `categories` ORDER BY `id` ASC");
if(mysql_num_rows($res) > 0){
while($row = mysql_fetch_assoc($res)){
$id = $row['id'];
$name = $row['name'];
if($cat_id === $id) {
echo '<option selected="selected" value="'.$id.'">'.$name.'</option>';
}else{
echo '<option value="'.$id.'">'.$name.'</option>';
}
}
}
?>
</select>
</div>
<div id="add_more_cat"></div>
<a href="javascript:void(0)" onClick="addInput('template', 'add_more_cat');">+ Add more</a>
以及如何將每個「elem_id _」+計數放入顯示結果的php查詢中? – Gadgetster
您可以使用ajax發送元素,也可以使用url發送。 –
你能告訴我你是怎麼做到的嗎? – Gadgetster