[eluser]Unknown[/eluser]
I dont know why i get this error.
Message: Undefined index: id
Index in database is ok, and checked
When i try to display data from DB in controller - its ok. I was trying everything, I think It's something with objects.
$vars['pList'] is an arry of objects so array $vars goes to View, and I should get access by using $pList['somthing']. Please help me!
Controller code (just a part witch is needed):
Code:
function index()
{
$this->load->model('productm');
$vars['pList'] = $this->productm->getProducts();
$this->load->view('product_view', $vars);
}
View code
Code:
<table>
<tr>
<td>Name</td>
<td>Desc</td>
<td>Price</td>
<td></td>
</tr>
<?php foreach ($pList as $item) { ?>
<tr>
<td><?php echo $item['id']; ?></td>
<td><?php echo $item['nazwa']; ?></td>
<td><?php echo $item['cena']; ?></td>
<td><a href="addtocart/<?php echo $item['id']; ?>">Add To cart</a></td>
</tr>
<?php } ?>
</table>
Model code
Code:
<?php
class Productm extends CI_Model
{
function _construct()
{
parent::_construct();
}
function getProductById()
{
$this->db->select('id');
return $this->db->get('produkty');
}
function getProducts()
{
$this->db->select('id, nazwa, cena');
return $this->db->get('produkty');
}
}
?>