0

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;
            }
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

1 Answers1

0

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.

Jonast92
  • 4,964
  • 1
  • 18
  • 32