php - Accessing data from multi-dimensional arrays and loops -


i'm struggling extracting data nested arrays.

here i'm @ code:

$active_tsquery = db_select("select * timesheets     status=\"cand\" or status=\"client\" order weekending asc");  var_dump($active_tsquery);  foreach($active_tsquery $key => $value) {     $candid[] = $active_tsquery[$key]["candid"];     $clientid[] = $active_tsquery[$key]["clientid"]; } 

the db_select function reference:

function db_select($query) {     $rows = array();     $result = db_query($query);      // if query failed, return `false`     if($result === false) {         return false;     }      // if query successful, retrieve rows array     while ($row = mysqli_fetch_assoc($result)) {         $rows[] = $row;     }     return $rows; } 

the db_query function reference:

function db_query($query) {     // connect database     $connection = db_connect();      // query database     $result = mysqli_query($connection,$query);      return $result; } 

the var_dump - being returned database.

array (size=15)   0 =>      array (size=29)   'ts_id' => string '5453' (length=4)   'clientid' => string '503' (length=3)   'candid' => string '714' (length=3)   'weekending' =>   'department' =>   'orderno' =>   'monhrs' =>   'tueshrs' =>   'wedshrs' =>   'thurshrs' =>)   'frihrs' =>   'sathrs' =>   'sunhrs' =>   'totalhrs' =>   'basichrs' =>   'othrs' =>   'ot2hrs' =>   'basicpay' =>   'basiccharge' =>   'otpay' =>   'otcharge' =>   'ot2pay' =>   'ot2charge' =>   'authname' =>   'authdate' =>   'ip' =>   'status' =>   'hue' =>   'huc' => 

what i'm trying loop through each of id's $active_tsquery (15 of them) in $candid, run query below , store results in array use later. should using foreach loop within first?

"select * timesheetlogin id=" 

thanks advice

got sorted using following:

$active_tsquery = db_select("select * timesheets status=\"cand\" or status=\"client\" order weekending asc");      //var_dump($active_tsquery);      foreach($active_tsquery $key => $value) {         $clientid = $value["clientid"];         $weekend = $value["weekending"];         $clientresult = db_select("select * timesheetlogin id=\"$clientid\"");         $candid = $value["candid"];         $candresult = db_select("select * timesheetlogin id=\"$candid\"");          foreach ($clientresult $key => $value) {             $company = $value["company"];         }         foreach ($candresult $key => $value) {             $candidate = $value["name"];         }     } 

Comments