在值列表中选择不同的ID - 给我错误的结果
$('#btnmails').on('click', function(){
let ids = $.map($('.atitle'), (e) => $(e).attr('data-id'));
ids = JSON.stringify(ids);
console.log(ids); // ["26","25","24","23","22","21"]
$.post('pro.php', {fn: 'btn_mails', args: [ids]}, function(data){
console.log(data); // 0 - but it is not true
});
});
pro.php
function btn_mails($ids){
global $db;
$sq = "select distinct mail from clients where id in ('" . $ids . "')";
$st = $db->prepare($sq);
$st->execute();
$arr = $st->fetchAll();
echo count($arr);
}
我在桌上都有所有六个ID,并且每个ID都带有不同的邮件
因此,结果应为6,而不是0
请帮助
$('#btnmails').on('click', function(){
let ids = $.map($('.atitle'), (e) => $(e).attr('data-id'));
ids = JSON.stringify(ids);
console.log(ids); // ["26","25","24","23","22","21"]
$.post('pro.php', {fn: 'btn_mails', args: [ids]}, function(data){
console.log(data); // 0 - but it is not true
});
});
pro.php
function btn_mails($ids){
global $db;
$sq = "select distinct mail from clients where id in ('" . $ids . "')";
$st = $db->prepare($sq);
$st->execute();
$arr = $st->fetchAll();
echo count($arr);
}
I have all six ids in table and each of them with a distinct mail
so result should be 6 and not 0
pls help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
我认为您的问题在您的php函数中
$ ids
是一个数组可能
I think that your problem is in your php function
Probably
$ids
is an array so you have to transform it in a string usingimplode
like this