I have a form to update an article.in this form I have tow select boxes one for section and another for sub section.An article should have a section but sub section is not necessary.In my update form if a section has subsections it should bring it.My problem is that in my update form if a section does not have any subsection it does not show the continuation of my form because in model it returns false.I tried to return null or an empty array but it could not solve my problem.
Model:
function get_subsection($sec_id,$subsec_name){
$this->db->selec("*");
$this->db->where('sec_id',$sec_id);
$this->db->where('subsec_name !=',$subsec_name);
$query=$this->db->get('sub_section');
if($query->num_rows() > 0)
{
return $query;
}
else
return false;
}
if this function returns false in update form it does not show the continuation of form and the edit submit button.I removed the else condition but it can not solve the problem.
Controller
function edit($id){
$data['rec']=$this->amodel->edit_art($id);//get the record to update
foreach($data['rec'] as $a)
{
$sections['items']=$this->amodel->section('$a->sec_id');//select all sections without that which selected by user
$subsetion['sub']=$this->amodel->subsection($a->sec_id,$a->subsec_name);//select all subsections of a section which selected by user
}
$this->load->view('edit_art',array_merge($data,$sections,$subsection));
}
the problem is with $subsetion
which can has no record in database.
please guide me what should I do to show all form element even the subsection be empty.
If i understand ur problem then you can try this
Model:
function get_subsection($sec_id,$subsec_name){
$this->db->selec("*");
$this->db->where('sec_id',$sec_id);
$this->db->where('subsec_name !=',$subsec_name);
$query=$this->db->get('sub_section');
return $query->result();
Controller:
function edit($id){
$data['rec']=$this->amodel->edit_art($id);//get the record to update
foreach($data['rec'] as $a)
{
$data['items']=$this->amodel->section('$a->sec_id');//select all sections without that which selected by user
$data['sub']=$this->amodel->subsection($a->sec_id,$a->subsec_name);//select all subsections of a section which selected by user
}
$this->load->view('edit_art',$data);
}
View :
<?php echo form_dropdown('items',$items,"",'class=""'); ?>
<?php echo form_dropdown('sub',$sub,"",'class=""'); ?>
Let me know is it ok or not. if not ok then post your view code.