php - query inside while loop only shows 1 result -


i'm making while loop in php , goes problem don't want id of user other stuff inside table, when go ahead , make query inside while loop , select second table (where id equal id of result first query), returns 1 result...

so code have:

public function getfriends($id) { global $params;  $get = $this->db->select("{$this->db['data']['friends']['tbl']}", "*",                           array(                                 "{$this->db['data']['friends']['one']}" => $id                           )                         );  if($get) {     while($key = $get->fetch())     {         $query = $this->db->query("select * {$this->db['data']['users']['tbl']}                                    {$this->db['data']['users']['id']} = :id",                                    array(                                          "id" => $key->{$this->db['data']['friends']['two']}                                    )                                  );          while($row = $query->fetch())         {             $params["user_friends"][] = [                 "id"   => $key->{$this->db['data']['friends']['two']},                 "name" => $row->{$this->db['data']['users']['username']},                 "look" => $row->{$this->db['data']['users']['figure']}             ];         }     } } else {     $params["update_error"] = $params["lang_no_friends"]; } } 

thanks in advance! please me out!

in absence of answers, don't know db framework using behind scenese...pdo, mysqli_, or (hopefully not) mysql_. but, in case, problem might second query stops first continuing. use pdo->fetchall() them all...but can't that...so, looping first , loading results array first thing see if problem:

public function getfriends($id) {     global $params;      $get = $this->db->select("{$this->db['data']['friends']['tbl']}", "*",                               array(                                     "{$this->db['data']['friends']['one']}" => $id                               )                             );      $firstresults = array();     if( $get ) {         while( $key = $get->fetch() ) {             $firstresults[] = $key;         }     }     else     {         $params["update_error"] = $params["lang_no_friends"];     }      foreach( $firstresults $key )     {         $query = $this->db->query("select * {$this->db['data']['users']['tbl']}                                    {$this->db['data']['users']['id']} = :id",                                    array(                                          "id" => $key->{$this->db['data']['friends']['two']}                                    )                                  );          while($row = $query->fetch())         {             $params["user_friends"][] = [                 "id"   => $key->{$this->db['data']['friends']['two']},                 "name" => $row->{$this->db['data']['users']['username']},                 "look" => $row->{$this->db['data']['users']['figure']}             ];         }     } } 

if doesn't work, need more data...e.g. query generated? when run manually return more 1 result? if rid of inner-query, fix it? etc.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -