使用Javascript过滤数据库中的结果,这将使DIV根据新参数重新加载其内容(Filtering results from a DB with a Javascript that will mak

编程入门 行业动态 更新时间:2024-10-28 03:25:25
使用Javascript过滤数据库中的结果,这将使DIV根据新参数重新加载其内容(Filtering results from a DB with a Javascript that will make a DIV reload it's contents based on new arguments)

我需要创建一个带有Checkboxes的表单来过滤从MySQL表中提取的结果。 理想情况下,在单击特定复选框后,将重新加载DIV,运行相应的PHP和PDO查询以筛选所选条件。

到目前为止这是我的代码,但它似乎不起作用......

有什么建议么?

谢谢!

<script> $(document).ready(function() { $("#colors").change(function() { console.log("changed..."); var data = $(this).serialize(); console.log(data); $("#indexMain").load("index.php?data="+data) }); }) </script> <div class="colors"> <form method="post" action="index.php"> <?php $colors = mysql_query("SELECT DISTINCT color_base1 FROM item_descr ORDER BY color_base1"); while ($colorBoxes = mysql_fetch_array($colors)) { echo "<input type='checkbox' name='color' value='".$colorBoxes[color_base1]."' /> ".$colorBoxes[color_base1]."<br />"; } ?> <input type="submit" onclick="document.formName.submit();" /> </form> </div>

我得到我的div中的值如下:

$color = $_POST['color']; if ($selectedColor == '') { $items = mysql_query("SELECT * FROM item_descr"); } else { $items = mysql_query("SELECT * FROM item_descr ORDER BY $color"); }

I need to create a form with Checkboxes to filter results extracted from a MySQL table. Ideally, after clicking on specific checkboxes, a DIV will be reloaded running the appropriate PHP and PDO query to filter on the selected criteria.

This is my code so far, but it doesn't seem to work...

Any suggestions?

Thanks!

<script> $(document).ready(function() { $("#colors").change(function() { console.log("changed..."); var data = $(this).serialize(); console.log(data); $("#indexMain").load("index.php?data="+data) }); }) </script> <div class="colors"> <form method="post" action="index.php"> <?php $colors = mysql_query("SELECT DISTINCT color_base1 FROM item_descr ORDER BY color_base1"); while ($colorBoxes = mysql_fetch_array($colors)) { echo "<input type='checkbox' name='color' value='".$colorBoxes[color_base1]."' /> ".$colorBoxes[color_base1]."<br />"; } ?> <input type="submit" onclick="document.formName.submit();" /> </form> </div>

and I get the value in my div as follows:

$color = $_POST['color']; if ($selectedColor == '') { $items = mysql_query("SELECT * FROM item_descr"); } else { $items = mysql_query("SELECT * FROM item_descr ORDER BY $color"); }

最满意答案

Colors是您的div的名称,但我认为您希望在您的名称为color复选框上触发更改,而不是s 。

$(document).ready(function() { $("input[type=checkbox][name=color]").change(function() { console.log("changed..."); var data = $(this).serialize(); console.log(data); $("#indexMain").load("index.php?data="+data) }); })

Colors is the name of your div, but I presume you want the on-change to be fired on your checkboxes, whose names are color, without an s.

$(document).ready(function() { $("input[type=checkbox][name=color]").change(function() { console.log("changed..."); var data = $(this).serialize(); console.log(data); $("#indexMain").load("index.php?data="+data) }); })

更多推荐

本文发布于:2023-07-20 12:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1199684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:这将   数据库中   加载   参数   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!