Welcome Guest, Not a member yet? Register   Sign In
Accessing DB result stored in a array.
#1

[eluser]cdonate[/eluser]
Hello, people!

So, I'm having some difficulties with accessing some information that is inside an array.

My model is getting some information from the DB and putting it to this array:

Code:
$ret['rows'] = $q->get()->result();
return $ret;

I return this to the controller and the controller put it inside another array, like so:

Code:
$usuarios = $this->admin_model->search($limit, $offset, $sort_by, $sort_order);
$data['users'] = $usuarios['rows'];

I also did this:

Code:
$data['fields'] = array(
   'id' => 'ID','name' => 'Nome',
   'email_address' => 'E-mail','RG' => 'RG',
   'OE' => 'OE','tel' => 'Telefone',
   'cel' => 'Celular','CPF' => 'CPF',
   'address' => 'Endereço','city' => 'Cidade',
   'state' => 'Estado','CEP' => 'CEP',
   'school' => 'Escola','type' => 'Tipo',
   'isOK' => 'Confirmado','isPaid' => 'Pago'
  );


where the fist item is the name of each field in my DB and the second is the name that is going to be displayed on my table, inside my view.

And then I send the $data array to the view, where its going to be displayed in a table, using 3 foreach()s, one for the Label and two for the data.

The DB has 10 fields, and when I am printing the 9th one I have to get the ID field again, it has already been printed in the beginning of the foreach.

How can I do this?

My foreach is like this:

Code:
<tbody>
    &lt;?php foreach($users as $user): ?&gt;
   <tr>
    &lt;?php foreach($fields as $field_name => $field_display): ?&gt;
    <td>
     &lt;?php
       if($field_display == 'Confirmado') {
         if($user->$field_name == 1) { echo 'Sim';}
         if($user->$field_name == 0) {
          
          echo form_open('login/administrator');
         echo form_checkbox($currentId, $currentId, FALSE);
         form_close();
         }
     }else{$user->$field_name;}
        
     ?&gt;
    </td>
    &lt;?php endforeach; ?&gt;
   </tr>
   &lt;?php endforeach; ?&gt;

</tbody>

When the field "Confirmado" is being written, I need to echo a form_checkbox() with the its name and value as the current 'id' for that row fetched from the DB.

I've tried $user['id'], $user["id"], $user->$field_name["id"], and I have no idea how to do it.

Can anybody help me?

The information is being displayed without problem on my table.

Thanks!!!




Theme © iAndrew 2016 - Forum software by © MyBB