Welcome Guest, Not a member yet? Register   Sign In
Undefined index - problem with listing data from DB
#1

[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>  
    &lt;?php foreach ($pList as $item) { ?&gt;
     <tr>

      <td>&lt;?php echo $item['id']; ?&gt;</td>
      <td>&lt;?php echo $item['nazwa']; ?&gt;</td>
      <td>&lt;?php echo $item['cena']; ?&gt;</td>
      <td><a href="addtocart/&lt;?php echo $item['id']; ?&gt;">Add To cart</a></td>  
      </tr>  
      
    &lt;?php } ?&gt;  
    </table>

Model code

Code:
&lt;?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');
}
}
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB