dimanche 11 janvier 2015

if in array with Codeigniter

i have conditional when insert data. this is conditional:


if id_status = 4, save fleet with format date('ymd',strtotime(str_replace('-', '/', $date))).$shift.$exca_id;


and if id_status != 4 save fleet with format date('ymd',strtotime(str_replace('-', '/', $date))).$shift.$status;


i try with this code but when i am insert id_status = 4 format always save with format : date('ymd',strtotime(str_replace('-', '/', $date))).$shift.$status;


this is my code in Controller:



function add_fleet()
{
$this->data['unit_list']= $this->munit_list->get_all_unit_list();
$this->data['status']= $this->mstatus->get_status();

$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('shift', 'Shift', 'required');
$this->form_validation->set_rules('exca_id', 'EXCA', 'required');
$this->form_validation->set_rules('id_status', 'Status', 'required');

if ($this->form_validation->run() == FALSE)
{
$this->data['contents'] = $this->load->view('fleet',$this->data, true);
$this->load->view('template/wrapper',$this->data);
}
else
{
$date = $this->input->post('date');
$shift = $this->input->post('shift');
$exca_id = $this->input->post('exca_id');
$status = $this->input->post('id_status');

if ((in_array("id_status", $data)) !== 4 ) {
$fleet = date('ymd',strtotime(str_replace('-', '/', $date))).$shift.$status;
}
else
{
$fleet = date('ymd',strtotime(str_replace('-', '/', $date))).$shift.$exca_id;
}

$data = array(
'date' => $date,
'shift' => $shift,
'exca_id' => $exca_id,
'fleet_status' => $fleet,
'id_status' => $status,
);

$query = $this->database_three->query("
select count(id_fleet) as jumlah from fleet
where fleet_status = '$fleet'");
$ans = $query->row();

if ($ans->jumlah > 0)
{
$this->session->set_flashdata('message', generateSuccessMessage('Fleet ID Sudah Digunakan'));
redirect(site_url('fleet/add_fleet'));
}
else
{
$this->mfleet->add_fleet($data);
$this->session->set_flashdata('message', generateErrorMessage('Data berhasil ditambah'));
redirect(site_url('fleet'));

}

}

}


can you help me how to solve this problem?


Aucun commentaire:

Enregistrer un commentaire