php - Read data from MySQL table and print only a specific item of each line in codeigniter view -


in model (model_users) have following :

public function members_list() {  $query = $this->db->get('users'); return $query->result(); } 

in controler have following function:

public function members_list() { $this->load->view('members_list_view'); } 

in view file have following code:

$this->load->model('model_users');    $membersarray = $this->model_users->members_list();  foreach ($membersarray  $v1) {        foreach ($v1 $v2) {                             echo "$v2\n";                             }                                 } 

my question following:

how echo userid of each line of users table?

with above code in view file got whole line of table.

your double structure loop

foreach ($membersarray  $v1) {            foreach ($v1 $v2) {     

actually runs on each row , on each element in each row, when echoing $vs should filed value, , @ end should fields of rows (maybe duplicates).

there no need run second loop, unless want loop on fields of each array out inserting them in right places, done this:

foreach ($membersarray  $v1) {      echo $v1['user_id']."\n";    }     

in case $v1 array/object fields of db table elements inside.

if query returns object , not array can call specific element this:

echo $v1->user_id."\n"; 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -