0

I want to display all records from database to my view page. Having a table customers, how can I display all records of this table?

Here is my customer_model.php file..

 function all_customss()
{
    $query=$this->db->query("select * from customers");
return $query->result();
}

Here are my controller.php file...

 function viewpage()
{
$result['data'] = $this->customer_model->all_customss();
    $this->load->view('models_view', $result);
}

And here is the link which will display all records after click...

<div class="col-md-12 col-sm-12 text-center"><a class="btn btn-default hvr-bounce-to-right" href="<?php echo site_url('/viewpage/');?>" role="button"><?php echo $this->lang->line('see_more'); ?></a>

and here is my view file...page_view.php

tr><td><?php
$i=1;
foreach($data as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$row->firstname."</td>";
echo "<td>".$row->lastname."</td>";
echo "<td>".$row->email."</td>";
echo "</tr>";
$i++;
}
?></td></tr>
Vickel
  • 7,879
  • 6
  • 35
  • 56
msginfosys
  • 57
  • 11

2 Answers2

0

You must put the name of your contoller before the name of your function like bellow:

<?php echo site_url('name_of_controoler/viewpage/');?>
0
 function all_customss()
 {
    $query=$this->db->query("select * from customers");
    return $query;
  }

  tr><td><?php
  $i=1;
  foreach($data->result () as $row)
  {
     echo "<tr>";
     echo "<td>".$i."</td>";
     echo "<td>".$row->firstname."</td>";
     echo "<td>".$row->lastname."</td>";
     echo "<td>".$row->email."</td>";
     echo "</tr>";
     $i++;
    }

I have modified your code. You should retrieve an array from a model. But it in your case you have already extracted the result in the model. And take a look in the view. I have modified your foreach parameter