donglong1465 2013-05-21 11:40
浏览 33
已采纳

选择列表中提供ID的行[重复]

This question already has an answer here:

I want to get all the list of registered players from an array

here is my function

function UpdateContact() 
    {
        try {
            $conn = $this->GetDBConnection();

            $linkedInId = trim($_REQUEST['linkedInId']);

            $statement = $conn->prepare('UPDATE users SET linkedInId = :linkedInId WHERE linkedInId = :linkedInId');
            $statement->bindParam(':linkedInId', $linkedInId, PDO::PARAM_STR);
            $statement->execute();

            //$updatedTime = time() - 120;
            $ids = implode(",",$_POST['ids']);
// $ids = (abc,def,geh,ijk,lac);

            $statement = $conn->prepare('SELECT * FROM users WHERE linkedInId IN (:ids)');
            $statement->execute($ids);
            $conn = null;

            if (!($row = $statement->fetchAll(PDO::FETCH_ASSOC))) 
                return false;
            else
                return $row;    

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

Just return false

Maybe because i am not able to bind the array with PDO Statement?

How can I fix this solution, i might want to add more binding parameters too later on, so i don't want to do execute($ids) either.

I have tried bindParam(':ids',$ids) too but of no avail

$items = array();
            //$statement->bindParam(':updatedTime', $updatedTime, PDO::PARAM_STR);

            foreach ($id as $ids)
            {
                $statement = $conn->prepare('SELECT * FROM users WHERE id = :id');
                $statement->bindParam(':id', $id, PDO::PARAM_STR);
                $statement->execute();
                if(($row = $statement->fetch(PDO::FETCH_OBJ))) 
                    $items[] = $id;
            }
</div>
  • 写回答

1条回答 默认 最新

  • doutuichan2681 2013-05-21 11:50
    关注

    I think it would make more sense to parse the array/list and perform the select for each id in the array/list.

    Pseudo code:

    init resultArray;
    For x in List
        select * from database where ids =: x
        if result
            add result to resultArray
    return resultArray
    

    But that's just the basic way of doing it, I'm not sure if you can do it more advanced.

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

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决