duan5362 2013-05-21 07:10
浏览 56
已采纳

更新查询以从php中的数组中找出已注册的ID

I am trying to find out which ids in an array are already registered or updated in the database. hOW can i customize my query to add array of ids $ids and make query to check for all the ids in the array if

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

Here is the code

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;
    }       
}
  • 写回答

1条回答 默认 最新

  • doushou3814 2013-05-21 07:16
    关注

    Assuming your id field was named id, then try this

    $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);
    

    Note, for this to work you will have to have those ids coming from your html form with name ids[]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类