php - Bind array into select query -


i try bind array of values in case $ownco in select query wont work. how can realize it, values becomes checked/passed in second query?

<?php  $hostname = 'localhost'; $user = 'root'; $password = ''; $username = $_cookie['username']; try {     $dbh = new pdo("mysql:host=$hostname;dbname=searchfood", $user, $password);      $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception); // <== add line     $sql = "select id_post             comments              username = $username             order id desc"; // oder (longitude between $loo , $lo or latitude  between $laa , $la) versuchen     if ($res = $dbh->query($sql)) {// need add line in code         // after fetchcolumn         $ownco = $res->fetchall();     } } catch (pdoexception $e) {     echo $e->getmessage(); }  $userid = $_cookie['userid']; try {     $dbh = new pdo("mysql:host=$hostname;dbname=searchfood", $user, $password);      $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception); // <== add line     $sql = "select id, autorid, autor, date, longitude, latitude, title, text, town, time             posts              id = $ownco             order id desc"; // oder (longitude between $loo , $lo or latitude  between $laa , $la) versuchen     if ($res = $dbh->query($sql)) {// need add line in code         // after fetchcolumn         $resultcom = $res->fetchall();     } } catch (pdoexception $e) {     echo $e->getmessage(); } ?> 

there several problems question.

  • first of all, accepted the answer doesn't answer it. cheating on rules?
  • second, first query never work, due wrong sql syntax , lack of prepared statements.
  • third, $ownco doesn't contain data structure expect.
  • fourth, bind array pdo quite simple question, explained in many answers , in pdo tag wiki.
  • fifth, don't need second query @ all. instead have use join in first query.

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -