In the model (model_users) I have the following :
public function members_list()
{
$query = $this->db->get('USERS');
return $query->result();
}
In the controler I have the following function:
public function members_list()
{
$this->load->view('members_list_view');
}
In the view file I have the following code:
$this->load->model('model_users');
$membersArray = $this->model_users->members_list();
foreach ($membersArray as $v1) {
foreach ($v1 as $v2) {
echo "$v2\n";
}
}
My question is the following:
How to echo only the USERID of each line of the USERS table?
With the above code in the view file I got the whole line of the table.
Your double structure loop
Actually runs on each row and then on each element in each row, so when echoing
$vs
you should get the filed value, and at the end you should get all fields of all rows (maybe even with duplicates).There is no need to run the second loop, unless you really want to loop on all fields of each array with out inserting them in the right places, usually what is done is something like this:
In this case
$v1
would be an array/object with all the fields of the DB table as elements inside.If the query returns an object and not an array you can call the specific element like this: