PHP foreach值在数组中

I am making an Staff Online section for members to see weather any staff member is in-game to help them or not. I began tackling this idea with an array of the Staff Members account ID's. It looks something like this:

$this->view->staffAdmins = array(64, 80, 96);

Then I used a foreach statement to get the following details for each account:

  • Are they logged in?
  • If so, use their ID from the array and get more information from the users table

My foreach statement looks like this:

foreach ($this->view->staffAdmins as $query) {
    //Are they logged in?
    $sql = "SELECT * FROM point WHERE uid = :ID AND zoneid > -1";
    $arr = array(":ID" => $query);
    $this->view->result = $this->database->DBCtr($sql, $arr);
    //Get their details!
    $sql = "SELECT * FROM users WHERE ID = :ID";
    $arr = array(":ID" => $query);
    $this->view->staffmem = $this->database->DBQry($sql, $arr);
    $this->view->name = $this->view->staffmem[0]['name'];
    $this->view->truename = $this->view->staffmem[0]['truename'];
    if ($this->view->result == 1){
        echo $this->view->truename;
    }
}

That returns the following output:

Hulu is Online
Cookiez is Online

Which is exactly what I need, but it outputs that at the very top of the page, which is not what I need. And when I try to put echo $this->truename; in the correct spot on the actual page it renders to, the output is

Cookiez is Online

It only gets the second staff member's ID (80) in the array, while we are both logged in at the same time.

Also, this is the code I am using to attempt to get same output as the one the working foreach statement. This is on the page the class renders too.

foreach ($this->staffAdmins as $staff){
    if ($this->result == 1){
        foreach ($this->staffmem as $logged){
        echo $logged['truename'];
        }
    }
}

you can make a array for logged in users like this

$arr_logged_users = array(); // array to store logged in users

foreach ($this->view->staffAdmins as $query) {
    //Are they logged in?
    $sql = "SELECT * FROM point WHERE uid = :ID AND zoneid > -1";
    $arr = array(":ID" => $query);
    $this->view->result = $this->database->DBCtr($sql, $arr);
    //Get their details!
    $sql = "SELECT * FROM users WHERE ID = :ID";
    $arr = array(":ID" => $query);
    $this->view->staffmem = $this->database->DBQry($sql, $arr);
    $this->view->name = $this->view->staffmem[0]['name'];
    $this->view->truename = $this->view->staffmem[0]['truename'];
    if ($this->view->result == 1){
        $arr_logged_users [] = $this->view->truename; // assign here to array
    }
}

now you can use $arr_logged_users where ever you want like this

foreach($arr_logged_users as $val)
{
    echo $val;
}