0

js

let ids = $.map($('.atitle'), (e) => $(e).attr('data-id'));
console.log(ids);
// ['6493e687161e0', '64a6776077613', '6489c85b3e6b1']
$.post('index_pro.php', {fn: 'btn_mails', args: [ids]}, function(data){
    console.log(data);
    //  error
});

error:

Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1367 Illegal double '6493e687161' value found during parsing in...

php

Need to select distinct mail where mail is not empty and id is in the above array

function btn_mails($ids){
    global $db;
    $str = implode(', ', $ids);
    $sq = "select distinct mail from arts where mail <> '' and id in (" . $str . ")";
    $st = $db->prepare($sq);
    $st->execute();
    $arr = $st->fetchAll();
    $str = '';
    foreach($arr as $el){$str .= $el['mail'] . "\n";}
    $str = rtrim($str, "\n");
    echo $str;
}
provance
  • 877
  • 6
  • 10

0 Answers0