user1733081 user1733081 - 13 days ago 6
MySQL Question

display database table in codeigniter

i am trying to display a table using codeigniter. i made a function to select all data from one table and display it using a foreach loop when the button is clicked. i am getting this error

Fatal error: Call to undefined method CI_DB_mysql_driver::result() in C:\Xampp\htdocs\Auction\application\models\bidding_model.php on line 47


this is my controller page

public function viewauction()
{

$this->load->model('bidding_model');
$data ['query'] = $this->bidding_model->viewauction();
$this->load->view('auction_view', $data);
}


This is the model

function viewauction()
{
$query = $this->db->select('products');
return $query->result() ;

}


this is the view

<tbody>
<?php foreach($query as $row): ?>
<tr>

<td><?php echo $row->product_id; ?></td>
<td><?php echo $row->auction_id; ?></td>
<td><?php echo $row->start_time; ?></td>
<td><?php echo $row->end_time; ?></td>


</tr>
<?php endforeach; ?>

</tbody>

Answer

Just change your model method code to

function viewauction()
{
    $query = $this->db->select('*')->from('products')->get();
    return $query->result();
}

Hope this helps. Thanks!!