mysql - PHP foreach value in array -
i making staff online
section members see weather staff member in-game them or not. began tackling idea array of staff members
account id's. looks this:
$this->view->staffadmins = array(64, 80, 96);
then used foreach
statement following details each account:
- are logged in?
- if so, use
id
array , more informationusers
table
my foreach
statement looks this:
foreach ($this->view->staffadmins $query) { //are logged in? $sql = "select * point uid = :id , zoneid > -1"; $arr = array(":id" => $query); $this->view->result = $this->database->dbctr($sql, $arr); //get details! $sql = "select * users 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 following output:
hulu online cookiez online
which need, outputs @ top of page, not need. , when try put echo $this->truename;
in correct spot on actual page renders to, output is
cookiez online
it gets second staff member's id (80)
in array, while both logged in @ same time.
also, code using attempt
same output 1 working foreach
statement. on page class renders too.
foreach ($this->staffadmins $staff){ if ($this->result == 1){ foreach ($this->staffmem $logged){ echo $logged['truename']; } } }
you can make array logged in users this
$arr_logged_users = array(); // array store logged in users foreach ($this->view->staffadmins $query) { //are logged in? $sql = "select * point uid = :id , zoneid > -1"; $arr = array(":id" => $query); $this->view->result = $this->database->dbctr($sql, $arr); //get details! $sql = "select * users 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 array } }
now can use $arr_logged_users
ever want this
foreach($arr_logged_users $val) { echo $val; }
Comments
Post a Comment