[eluser]Roy MJ[/eluser]
Hi,
Can anyone tell me what im doing wrong. Im trying to get value from database for editing purpose. But error showing :
Code:
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined variable: productcategory</p>
<p>Filename: mypackages/edit.php</p>
<p>Line Number: 98</p>
</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: Invalid argument supplied for foreach()</p>
<p>Filename: mypackages/edit.php</p>
<p>Line Number: 98</p>
The controller which im using to get the data is as follows:
Code:
$this->data['productcategory'] = $this->Mypackages_model->select_category();
$this->data['productstack'] = $this->Mypackages_model->select_stack();
The model part is as follows:
Code:
function select_stack()
{
$this->db->select('id,product_name');
$this->db->order_by('product_name',"asc");
$result_product = $this->db->get('product');
return $result_product->result();
}
function select_category()
{
$this->db->select('category_id,category_name');
$this->db->order_by('category_id',"desc");
$result_productcategory = $this->db->get('product_category');
return $result_productcategory->result();
}
The view is as follows:
Code:
<div>
<label>Product Group<span class="mandatory">*</span></label>
<select name="product_group" id="product_group" class="list_1">
<option value="">- - Select Category - -</option>
<?php foreach($productcategory as $row) {?>
<option value="<?php echo $row->category_name?>" <?php echo set_select('product_group',$row->category_name);?> ><?php echo $row->category_name?></option>
<?php } ?>
</select>
</div>
<div>
<label>Stack<span class="mandatory">*</span></label>
<select id="product_id" name="product_id" class="list_1" >
<option value="">- - Select Stack - -</option>
<?php foreach($productstack as $row) {?>
<option value="<?php echo $row->product_name?>" <?php echo set_select('product_id',$row->product_name);?> ><?php echo $row->product_name?></option>
<?php } ?>
<option value="11111"> - - Other - - </option>
</select>
</div>
Why is it showing undefined error?.. Its working fine for add page. This is while editing. But the select box values are from the same table and its value is static.