nsutgio nsutgio - 1 year ago 70
PHP Question

Selecting records from a database table in php using codeigniter and pass to a view

I'm making a query in php using codeigniter to get the data that I wanted from a database. To be able to get all values for a specific column, I stored it into an array and passed it into a view. But I can do it only for one column.

Here's my code:

$query = $this->db->query('SELECT name,description FROM module');

$result = $query->result_array();

foreach($result as $key => $rowdata){

$resultdata['values'][$key] = $rowdata['name'];



With this scenario I can get all name from the module table. But my problem is, I also wanted to get all the description in the module table, but I don't know how can I implement it and be able to pass it into the view. Hope someone could help me with this. Thanks!

Answer Source

hi in you way you will do loop twice in controller and then in view to print it check this out

//in controller

 $query = $this->db->query('SELECT name,description FROM module');

    $resultdata['results'] = $query->result_array();



foreach($results as $result)
    echo $result['name'],' ',$result['description'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download