Welcome Guest, Not a member yet? Register   Sign In
Undefined property: stdClass
#1

[eluser]Unknown[/eluser]
Hi im having these two errors and I can`t find whats wrong... propably that I just started to use codeigniter.

Message: Undefined property: stdClass::$quantity
Filename: products/index.php
Line Number: 28

Message: Undefined property: stdClass::$website
Filename: products/index.php
Line Number: 32

products/index.php

Code:
<?php
Header('Cache-Control: no-cache');
Header('Pragma: no-cache');
$this->load->view('header');
$this->load->view('invoices/invoice_new');
?>

<h2>&lt;?php echo $page_title;?&gt;</h2>

&lt;?php if ($message != ''):?&gt;
    <p class="error topmessage">&lt;?php echo $message;?&gt;</p>
&lt;?php endif;?&gt;

<p class="button">
        &lt;?php echo anchor('products/newproduct', $this->lang->line('products_create_new_product'), array('class'=>'productnew'));?&gt;
</p>


&lt;?php foreach($all_products->result() as $product): ?&gt;

    <h3 class="display productHeader productHeader&lt;?php echo $product->id;?&gt;">
    <a class="displayLink">id;?&gt;" href="#productHeader&lt;?php echo $product->id;?&gt;">&lt;?php echo $product->name;?&gt;</a></h3>

    <div class="productInfo" id="productInfo&lt;?php echo $product->id;?&gt;">

        <p>
            &lt;?php if ($product->name != '') {echo $product->name;}?&gt;
            &lt;?php if ($product->quantity != '') {echo $product->quantity;}?&gt;
            &lt;?php if ($product->jm != '') {echo $product->jm;}?&gt;
            &lt;?php if ($product->value != '') {echo ', ' . $product->value;}?&gt;
            
            &lt;?php echo auto_link(prep_url($product->website));?&gt;
        </p>
                    
        <p class="product_options">
            &lt;?php echo anchor('products/notes/'.$product->id, $this->lang->line('products_notes'), array('class' => 'product_notes'));?&gt; |
            &lt;?php echo anchor('products/edit/'.$product->id, $this->lang->line('products_edit_product'), array('class' => 'product_edit'));?&gt; |
            &lt;?php echo anchor('products/delete/'.$product->id, $this->lang->line('products_delete_product'), array('class'=>'lbOn deleteConfirm product_delete'));?&gt;
        </p>        
        </div>

controllers/products.php

Code:
function index()
    {
        $data['clientList'] = $this->clients_model->getAllClients();// activate the option
        $data['extraHeadContent'] = "&lt;link type=\"text/css\" rel=\"stylesheet\" href=\"" . base_url()."css/products.css\" /&gt;\n";
        $data['extraHeadContent'] .= "[removed][removed]\n";
        

        if ($this->session->flashdata('product_edit'))
        {
            $data['message'] = $this->lang->line('products_edited');
            $data['extraHeadContent'] .= "[removed]\nfunction openCurrent() {\n\tEffect.toggle ('product_info".$this->session->flashdata('product_edit')."', 'Blind', {duration:'0.4'});\n}\naddEvent (window, 'load', openCurrent);\n[removed]";
        }
        else
        {
            $data['message'] = $this->session->flashdata('message');
        }

        $data['total_rows'] = $this->products_model->count_all_products();

        // Run the limited version of the query
        $data['all_products'] = $this->products_model->get_all_products();

        $this->_validation_products(); // validation info for id, name, jm(type of measurment), value

        $data['page_title'] = $this->lang->line('menu_products');
        $this->load->view('products/index', $data);
    }

products_model.php
Code:
function get_all_products()
    {

        $this->db->orderby('name', 'asc');

        return $this->db->get('products');
    }


Appreciate the help
#2

[eluser]Twisted1919[/eluser]
orderby() is deprecated as far as i know, so this can be a reason.
Other than that, the thing is that you don't get any records back from your query, i can say that if you var_dump($all_products) in your view, you won't have any rows to iterate through.

i would reqrite the query as:
Code:
function get_all_products()
    {

        $q=$this->db->select('*')->from('products')->order_by('name', 'asc')->get();
        return $q->num_rows() > 0 ? $q->result() : NULL ;
    }
then in your view:
Code:
if(!empty($all_products))
{
   foreach($all_products AS $product)
   {
      // do things here with $product->
   }
}




Theme © iAndrew 2016 - Forum software by © MyBB