0
view:
<?phpforeach($row as $b):?> 

<?php echo $b->Product_Name ?></h3>
                      <?php echo $b->Price ?></p>



                     </div>
                     <?php if ($b->Option_name):?>
                            <?php echo form_label($b->Option_name, 'option_'.$b->Product_ID ); ?> 

                           <?php echo form_dropdown(
                           $b->Option_name,
                           $b->Option_value,
                           NULL,
                           'Product_ID= " option_' .$b->Product_ID. ' " '


                           );?>

                        <?php endif; ?>

controller:
public function product_detail($Product_ID){

            $this->load->model('model_products');

        $data['row']= $this->model_products->get_detail($Product_ID);



        $this->load->view('product_detail',$data);
}

model:
   function get_detail($Product_ID){
                       $this->db->from('products');
        $this->db->where('Product_ID',$Product_ID);
        $query= $this->db->get('');
       if  ($query->num_rows()==1) {
            foreach($query->result() as $row){
                $data[]=$row;
            }

       }
        return $data;
        }

codeignitor 
i m get warning : Invalid argument supplied for foreach()   I thing it is dropdown                  

Edited by Nabeel_2

3
Contributors
6
Replies
45
Views
3 Years
Discussion Span
Last Post by pzuurveen
0

ya output is Undefined variable: data
but when <?php print_r($row);?>
then out is :
Array ( [0] => stdClass Object ( [Product_ID] => 9 [cat_id] => 2 [s_cat_id] => 0 [Product_Name] => TShirt [Product_Description] => [Product_Detail] => Pure Cotton [Price] => 400.00 [Option_name] => Size [Option_value] => Small,Medium,Large [Image] => Tshirt.jpg [Units_in_stock] => 0 [Re-Order_level] => 0 [display] => 0 ) )

0

can you change and test your model with this code?

function get_detail($Product_ID)
{
    $this->db->from('products');
    $this->db->where('Product_ID',$Product_ID);
    $query= $this->db->get('');
    if ($query->num_rows() >0 ) {

    return $query->result();

    }

     /// return false;
}

this

return $query->result();

allows you to access the $row in view as object.,

while this one will allow you to index the array e.g. $row['column_name'].

    return $query->result_array();
0

by the way, you don't really need to do this

 $query= $this->db->get('');

this should be the proper way

 $query= $this->db->get();

the reason is that the database active record class method for get is declared like this

public function get($table = '', $limit = null, $offset = null)

What does the above method tells us is that the parameter table has been predefined as '' as empty, while the $limit and the $offset parameters are predefined as null.

I know this bring up many arguments about all the parameters are equally the same. In theory, they may appear to be equal but the null will return false if evaluated if it is set, while the '' or "" will definitely return true. However, the most revealing truth that these 3 parameters are not equally the same at any point is this. If '' or "" is evaluated as is_null() it is definitely false, but all will evaluate to true if evaluated as empty(). Whereas in the comparator operators, these three will also have a hair line difference. Null is true if compared as == and ===, while '' and "" will become false in === and true in ==.

That is pretty important stuffs in dealing things in Obejcts and methods. So, we don't really do this

if($query->num_rows()== 1)

the reason is that the numerical rows carries a default value of 0 ONLy in this regards, so if we do this

if($query->num_rows()> 0)

that should give us true or false response. I mean false conversion to true if the default is 0 at idle.

0

problably just a past error line 2:
<?phpforeach($row as $b):?>
must be
<?php foreach($row as $b):?>

but where is the endforeach;

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.