$('#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
请帮忙
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我认为你的问题出在你的 php 函数
可能
$ids是一个数组,因此您必须使用implode将其转换为字符串像这样
function btn_mails($ids){ global $db; $sq = "select distinct mail from clients where id in (" . implode(', ', $ids) . ")"; $st = $db->prepare($sq); $st->execute(); $arr = $st->fetchAll(); echo count($arr); }