php - Selecting rows where ids are provided in a list -
this question has answer here:
- can bind array in() condition? 19 answers
i want list of registered players array
here function
function updatecontact() { try { $conn = $this->getdbconnection(); $linkedinid = trim($_request['linkedinid']); $statement = $conn->prepare('update users set linkedinid = :linkedinid 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 * users 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 not able bind array pdo statement?
how can fix solution, might want add more binding parameters later on, don't want execute($ids)
either.
i have tried bindparam(':ids',$ids)
of no avail
$items = array(); //$statement->bindparam(':updatedtime', $updatedtime, pdo::param_str); foreach ($id $ids) { $statement = $conn->prepare('select * users id = :id'); $statement->bindparam(':id', $id, pdo::param_str); $statement->execute(); if(($row = $statement->fetch(pdo::fetch_obj))) $items[] = $id; }
i think make more sense parse array/list , perform select each id in array/list.
pseudo code:
init resultarray; x in list select * database ids =: x if result add result resultarray return resultarray
but that's basic way of doing it, i'm not sure if can more advanced.
Comments
Post a Comment