Reputation: 3520
I want to develop a edit form for newsletter. I have done this but i can't load category list in same view.
if user click on newsletter its open in edit view, in this edit view i want to give him a option for category selection option. categories are stored in different table name cat.
i have tried it but its showing only one category.
Please help me am new in Php
Upvotes: 0
Views: 442
Reputation: 2281
Well, without any actual code examples, this is going to de pretty tough... Presumably the edit view is a form, and you are using the form helper to generate a dropdown field.
The first thing you need are the categories in the right format to be displayed in the dropdown.
From the CodeIgniter docs :
$options = array(
'small' => 'Small Shirt',
'med' => 'Medium Shirt',
'large' => 'Large Shirt',
'xlarge' => 'Extra Large Shirt',
);
where the array keys are your options values and the array values are the text displayed.
You need to get your categories in this format with your model. I tend to use the id as the option value, so you could have a function like this in your model:
function get_cat(){
$q=$this->db->get('cat');
if ($q->num_rows()>=1){
foreach($q->result() as $row){
$data[$row->id]=$row->name;
}
return $data
}else{
return false;
}
}
and assuming your controller passes the result of that function to the view, you can just do this in your view :
echo form_dropdown('categories', $data);
As a closing note, you might want to start on PHP by developping some things from scratch, not using a framework, you should learn a lot more that way. Just my opinion.
Upvotes: 1