gpt4 book ai didi

php - 我想使用带有 AJAX 的文本框搜索

转载 作者:行者123 更新时间:2023-11-29 03:01:29 28 4
gpt4 key购买 nike

您好,我正在尝试弄清楚如何使用我的文本框通过 AJAX 进行实时搜索,然后使用数据库中的数据更新页面。但我希望它与以下标题一起输出:

            <th>Medewerker</th>
<th>Datum overboeking</th>
<th>Juliette geinformeerd</th>
<th>Boekingsnummer</th>
<th>Land</th>
<th>Huiscode</th>
<th>Aanbieder</th>
<th>Contractvorm</th>
<th>Huursom</th>
<th>Periode van</th>
<th>Periode tot</th>
<th>Distributiekanaal</th>
<th>Naam klant</th>
<th>Reden</th>
<th>Nieuwe boeking</th>
<th>Reden geen nieuwe boeking</th>
<th>Boete aanbieden</th>
<th>Administratie geinformeerd voor inhouding boete</th>
<th>Bedrag van boete</th>
<th>Coulance Happyhome</th>
<th>Opmerking</th>
<th>Id</th>

PHP

$pdo = new PDO('mysql:host=localhost;dbname=records', 'root', '***');
$select = 'SELECT *';
$from = ' FROM overboekingen';
$opts = isset($_POST['filterOpts'])? $_POST['filterOpts'] : array('');

if (in_array("naam_klant", $opts)){
"naam_klant = '{$opts['naam_klant']}%' ";
}

$sql = $select . $from . $where;
$statement = $pdo->prepare($sql);
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);

echo($json);

HTML

        <td>
<input type="text" name="naam_klant" size="20" id="naam_klant" onkeyup="lookup(this.value);" onblur="fill();" >
<div class="suggestionsBox" id="suggestions" style="display: none;">
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>
</td>

AJAX

<script>
function makeTable(data) {
var tbl_body = "";
$.each(data, function() {
var tbl_row = "";
$.each(this, function(k , v) {
tbl_row += "<td>"+v+"</td>";
})
tbl_body += "<tr>"+tbl_row+"</tr>";
})
return tbl_body;
}

function getEmployeeFilterOptions(){
var opts = [];
$checkboxes.each(function(){
if(this.checked){
opts.push(this.name);
}
});
return opts;
}

function getEmployeeFilterOptions2(){
var opts = [];
$onchange.each(function(){
if(this.checked){
opts.push(this.name);
}
});

return opts;
}

function updateEmployees(opts){
$.ajax({
type: "POST",
url: "submit.php",
dataType : 'json',
cache: false,
data: {filterOpts: opts},
success: function(records){
$('#employees tbody').html(makeTable(records));
}
});
}

var $checkboxes = $("input:checkbox");
$checkboxes.on("change", function(){
var opts = getEmployeeFilterOptions();
updateEmployees(opts);
});

updateEmployees();

</script>

但是我卡住了从这里开始做什么,代码在 atm 上不起作用。

最佳答案

我建议您首先修复返回结果的 php 脚本。

一个明显的错误是您在此 if 子句中的语句:

 if (in_array("naam_klant", $opts)){
"naam_klant = '{$opts['naam_klant']}%' ";
}

我认为你正在尝试设置 where 变量,所以它应该是这样的:

 if (in_array("naam_klant", $opts)){
$where = " WHERE naam_klant = '{$opts['naam_klant']}%' ";
}

关于php - 我想使用带有 AJAX 的文本框搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22932640/

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