0

我试图找出数组中的哪些 id 已经在数据库中注册或更新。我如何自定义我的查询以添加 id 数组$ids并进行查询以检查数组中的所有 id 如果

1- They are Registered And their visibility is 1 and their update_time > :update_time

这是代码

function GetOnlineContacts() 
{
    try {
        $conn = $this->GetDBConnection();
        $update_time = time() - 120;

        $ids = array($_POST['ids']);

        $statement = $conn->prepare('SELECT linkedInId FROM users WHERE update_time > :update_time AND visibility = 1');
        $statement->bindParam(':update_time', $update_time, PDO::PARAM_STR);
        $statement->execute();

        $conn = null;




        } catch(PDOException $e) {
        throw $e;
    }       
}
4

1 回答 1

0

假设您的 id 字段被命名id,然后试试这个

$ids = implode(",",$_POST['ids']);
$statement = $conn->prepare('SELECT linkedInId FROM users WHERE update_time > :update_time AND visibility = 1 AND id IN(:ids)');
$statement->bindParam(':update_time', $update_time, PDO::PARAM_STR);
$statement->bindParam(':ids', $ids, PDO::PARAM_STR);

请注意,要使其正常工作,您必须让那些ids来自您的 html 表单的名称ids[]

于 2013-05-21T07:16:28.623 回答