php - Mysqli fetching data from two columns -


i have 3 tables users(id,name,etc..), trips(id,user_id,from,to,destionation) , vactions(id,user_id,from,to,destionation). use mysqli , can not figure out how need fetch table this

 array (     [0] => array         (             [id] => 1             [current_status] => 0             [username] => user1             [fullname] => eric norman             [trips] = > array             (                 [0] => array                  (                     [date_from] = 02/06/14                     [date_to] = 05/06/14                     [destination] = "grece"               )            [vacations] = >          )      [1] => array         (             [id] => 2             [current_status] => 0             [username] => user2             [fullname] => joe grey             [trips] = > array             (                 [0] => array                  (                     [date_from] = 02/06/14                     [date_to] = 05/06/14                     [destination] = "grece"               )             [vacations] = >           )  )

i've tried left join doesn't work , code users :

      conn = new mysqli($host,$user,$password,$db);     $result = mysqli_query($conn, "select id, current_status, username, concat(first_name,'  ',last_name) fullname user");     while ($row = $result->fetch_assoc()) {             $users[] = $row;         }  

i think best way users, use foreach trips , vacations. because i'm not sure can obtain kind of array result using simple sql query, think ou need orm.

$users = getallusers(); foreach($users $user){   $user['trips'] = gettripsbyuserid($user['id']);   $user['vacations'] = getvacationsbyuserid($user['id']); } 

of course need code 3 methods "getallusers" ; "gettripsbyuserid" , "getvacationsbyuserid" simple select query database clause.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -