作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在尝试弄清楚如何使用我的文本框通过 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/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!