lil lil - 5 months ago 9
PHP Question

How to extract field values from query result

I have problem in extracting data from query result. I have the following method in my model that returns a result of many rows

function method(){
$this->db->select('*');
$this->db->from('table_name');

$query = $this->db->get();

return $query->result();
}


from my controller I call the above function like this

$data['returned_records']= $this->model_name->method();


and now I want to display returned_records in table format in a view. How do I go about that?

Answer

To display the output in view in tablur form The code would be something like this:

<table border="1">  
          <tbody>  
             <tr>  
                <td>Heading 1</td>  
                <td>Heading 2</td>  
              // add more according to requirement
             </tr>  
             <?php  
             foreach ($returned_records->result() as $row)  
             {  
                ?><tr>  
                <td><?php echo $row->Column_name;?></td>  
                <td><?php echo $row->Column_name;?></td>
               // add more according to requirement  
                </tr>  
             <?php }  
             ?>  
          </tbody>  
       </table>  
Comments