从多维数组和循环访问数据

I'm struggling with extracting data from nested arrays.

Here is where I'm at with my code:

$active_tsquery = db_select("SELECT * FROM timesheets WHERE     status=\"cand\" OR status=\"client\" ORDER BY weekending ASC"); 
var_dump($active_tsquery);

foreach($active_tsquery as $key => $value) {
    $candid[] = $active_tsquery[$key]["candid"];
    $clientid[] = $active_tsquery[$key]["clientid"];
}

The db_select function for reference:

function db_select($query) {
    $rows = array();
    $result = db_query($query);

    // If query failed, return `false`
    if($result === false) {
        return false;
    }

    // If query was successful, retrieve all the rows into an array
    while ($row = mysqli_fetch_assoc($result)) {
        $rows[] = $row;
    }
    return $rows;
}

The db_query function for reference:

function db_query($query) {
    // Connect to the database
    $connection = db_connect();

    // Query the database
    $result = mysqli_query($connection,$query);

    return $result;
}

The var_dump is good - everything is being returned from the 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 to do is loop through each of the id's from $active_tsquery (15 of them) in $candid, run the query below and store the results in an array for use later. Should I be using another foreach loop within the first?

"SELECT * FROM timesheetlogin WHERE id="

Thanks for any advice

Got it sorted using the following:

$active_tsquery = db_select("SELECT * FROM timesheets WHERE status=\"cand\" OR status=\"client\" ORDER BY weekending ASC"); 
    //var_dump($active_tsquery);

    foreach($active_tsquery as $key => $value) {
        $clientid = $value["clientid"];
        $weekend = $value["weekending"];
        $clientresult = db_select("SELECT * FROM timesheetlogin WHERE id=\"$clientid\"");
        $candid = $value["candid"];
        $candresult = db_select("SELECT * FROM timesheetlogin WHERE id=\"$candid\"");

        foreach ($clientresult as $key => $value) {
            $company = $value["company"];
        }
        foreach ($candresult as $key => $value) {
            $candidate = $value["name"];
        }
    }