Welcome Guest, Not a member yet? Register   Sign In
undefined index
#1

[eluser]Unknown[/eluser]
Sorry if this is not the place to post this, but I really need your help.
I've been getting a lot of undefined index errors from my model and I don't know why.
This is the code:
Code:
function get_items(){
        
        $dynamiclist = "";
        $query = $this->db->query('SELECT id FROM products');
        $productCount = $query->num_rows();
        if($productCount > 0){
            
            foreach($query->result_array() as $row){
                $id= $row["id"];
                $product_name= $row["product_name"]; //error
                $price = $row["price"]; //error
                $category = $row["category"]; //error
                $subcategory = $row["subcategory"]; //error
                $details = $row["details"]; //error
                $date_added = $row["date_added"]; //error
                ...
Basically, I get errors for those variables I have marked.
Can anyone enlighten me?
#2

[eluser]bhenbe[/eluser]
sure...
you don't notice the fields.

your query :
Code:
SELECT [b]id[/b] FROM products

You just call ID, not the rest.
#3

[eluser]Unknown[/eluser]
God, I thought I changed that already to *.
Thanks a lot.
And please excuse my idiocy.
#4

[eluser]InsiteFX[/eluser]
If you use Active Record you can do just this:
Code:
$query = $this->db->get('products');

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB