gpt4 book ai didi

php - jQuery 执行 PHP MySQL 查询

转载 作者:行者123 更新时间:2023-11-29 02:32:25 24 4
gpt4 key购买 nike

这是我得到的。我正在尝试让 jquery 运行 mysql 查询。

这是我的 PHP:

<select name="kingdom" id="kingdom" >
<option value="standard">-- Kingdom --</option>
<?php
$the_d = $_POST['d'];
$filter = mysql_query("SELECT DISTINCT sci_kingdom FROM tbl_lifedata WHERE sci_domain = '$the_d'");
while($row = mysql_fetch_array($filter, MYSQL_NUM))
{
$row['name'];
//echo "<option value='$row[0]'>$row[0]</option>";
}
?>
</select>

还有我的 jQuery:

$('#domain').change(function () {

var selectval = $('#domain').val();

$.post("search.php", {
d: selectval
}, function (data) {
$('.result').html(data);
});
});

现在我只想让 jQuery 吐出 mysql 结果的值。当我完成这项工作时,我可以让它们填充一个选择框。我现在得到的是 search.php 的 html,但与 mysql 查询无关。

最佳答案

您实际上应该打印从数据库中检索的内容。

<select name="kingdom" id="kingdom" >
<option value="standard">-- Kingdom --</option>
<?php
$the_d = mysql_real_escape_string($_POST['d']);//thanks to @Mansfield
$filter = mysql_query("SELECT DISTINCT sci_kingdom FROM tbl_lifedata WHERE sci_domain = '".$the_d."'");
while($row = mysql_fetch_array($filter, MYSQL_NUM))
{
echo "<option value='$row[0]'>$row[0]</option>";

}

?>
</select>


//or you can also use mysql_fetch_array($filter, MYSQL_ASSOC) if you want to print $row['name']

更新的答案:

<script src="jquery.min.js"></script>
<input type='text' class="domain" id="domain"/>
<div class="result" id="result"></div>
<script>
$('#domain').change(function() {

var selectval = $('#domain').val();

$.post(
"test.php",
{ d : selectval },
function(data) {
$('.result').html(data);//my bad should be displaying data retrenched
}
);
});
</script>

///test.php contents:

<?php
print $the_d = mysql_real_escape_string($_POST['d']);// see if the scripts are working fine until here, if so, then see below.
//test your mysql result by doing a print_r($row.)
?>

发布 print_r($row) 的结果;

关于php - jQuery 执行 PHP MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11130433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com