i have two radio button and one check box..If the radio button alone is checked i want to load one view page(Receipt_view) if both radio button and check box is checked i want to load another view page(Receipt_View1)...My problem is if both radio button and check box is checked i get the output as 2 view pages(that is both the view pages are loaded both Receipt_view and Receipt_view 1 are loaded) but i want Receipt_view1 to be loaded when both the radio button and check box is checked.. Controller Code:
if ($this->input->post('all'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get()->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
if($this->input->post('all'))
{
if($this->input->post('item')){
if ($this->input->post('all'))
{
if($this->input->post('item')){
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->select('vno,Prdtname,Qty,bundle');
$this->db->from('purchaseitem');
$this->db->order_by("vno", "asc");
//$this->db->join('purchasebill', 'purchasebill.no = purchaseitem.billno','left outer');
//$this->db->join('parmaster','parmaster.pcode = purchasebill.partyname');
$this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select();
$this->db->from('purchasebill');
$this->db->order_by('voucherno');
$this->db->group_by('voucherno');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query1'] = $query;
$this->load->view('Receipt_View1',$data);
}}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->where('PName',$name);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
//$this->db->join('salesbill', 'salesbill.no = salesitem.billno','left outer');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
}
Html Page:
<input type="radio" class='rd'name="all" value="op1" checked="">All
<input type="radio" name="selected" class='rd' value="op2"> Selected
<input type="checkbox" name="item" >Item description
All and selected is the radio button name and item is the check box name..Help me to solve this issue..
You haven't told us what happens when neither of them is checked, so I'm not mentioning this case here, but you can do something like:
if ($this->input->post('all')) {
//do something with purchasebill, no need to repeat the code
//check if the checkbox is checked:
if($this->input->post('item')) {
// do something with purchaseitem
$this->load->view('Receipt_View1',$data);
} else {
$this->load->view('Receipt_View',$data);
}
}
write functions in 'else' block , your not using 'else' with if condition..
By using elseif and && operator we can load according to the condition
if ($this->input->post('all'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get()->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
else if(($this->input->post('all')) &&($this->input->post('item')))
{
$this->db->select('vno,Prdtname,Qty,bundle');
$this->db->from('purchaseitem');
$this->db->order_by("vno", "asc");
$this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View1',$data);
}}
else if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->where('PName',$name);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
//$this->db->join('salesbill', 'salesbill.no = salesitem.billno','left outer');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
}