我有一个下拉列表,需要动态更改以下php mysql查询。特别是WHERE部分。所以下拉菜单有CATERING,ENTERTAINMENT,VACATIONS等。所以如果有人选择VACATIONS,下面的查询会将娱乐与tblclients.category ='Vacations'交换,页面上的结果会发生变化。
PHP
$query = mysql_query("SELECT * FROM tblClients WHERE tblclients.package = 'standard' and tblclients.category = 'Entertainment' LIMIT 0, 9", $connection);
JQUERY - 我想出了如何让以下脚本知道选择了哪个下拉列表选项,但只知道如何显示/隐藏DIV。
<script>
$(document).ready(function(){
$('.dropdown .Catering').click(function(){
$('#page_featured_container').show();
});
$('.dropdown .Entertainment').click(function(){
$('#page_featured_container').show();
});
$('.dropdown .Vacations').click(function(){
$('#page_featured_container').show();
});
</script>
HTML 仅供完整参考,我的下拉列表就是这样。
<section class="main">
<div class="wrapper">
<div id="dd" class="wrapper-dropdown-3" tabindex="1">
<span>View By Category</span>
<ul class="dropdown">
<?php while ($rows = mysql_fetch_array($query_category)) { ?>
<li><a class="<?php echo $rows['category']; ?>"><?php echo $rows['category']; ?></a></li>
<?php } ?>
</ul>
</div>
</div>
</section>
所以,理论上,我的JQUERY想要这个......
<script>
$(document).ready(function(){
$('.dropdown .Catering').click(function(){
CHANGE PHP WHERE STATEMENT AND DISPLAY NEW RESULTS.
答案 0 :(得分:3)
您可以通过使用jquery:
的Ajax查询来执行此操作data want;
set have;
retain acntnum2;
acntnum=coalesce(acntnum,acntnum2);
acntnum2=acntnum;
run;
如果您更喜欢使用POST方法 你必须添加:
$(".dropdown .Catering").on("click", function()
{
// getting the classname of clicked category to write your query
var category = $(this).attr("class");
$.ajax
({
url:"controller.php?category="+category, // supposed you grab the query like that
method: "get", // or post as you want
success: function(data) // where data is the php returned newest list
{
// this line will overwrite the html content of 'page_featured_container'
$("#page_featured_container").html(data);
}
});
});