Hello there. I'm from Turkey. I use google translate because i don't speak english.
I am sending an array to the Controller with AJAX. There are 3 different IDs in the array I sent. I will pull data from the database with these IDs, but I don't know how to separate them.
Ajax
Code:
$.ajax({
url: '<?php echo base_url('varyasyonlar/o_getir') ?>',
type: 'POST',
data: {opts: opts},
dataType: 'JSON',
cache: false,
success: function (data) {
const toast = swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000,
padding: '2em'
});
toast({
type: 'success',
title: 'Çalıştı.',
padding: '2em',
})
},
error: function (data) {
swal({
title: 'Bir hata oluştu!',
type: 'error',
padding: '2em'
});
}
});
Controller
Code:
public function o_getir() {
$data = $this->input->post('opts');
$this->varyasyonlar_model->o_get2($data);
foreach ($data as $key => $row) {
$output['opsiyon_id'][$key] = $row->opsiyon_id;
$output['opsiyon_baslik'][$key] = $row->opsiyon_baslik;
}
echo json_encode($output);
}
Model
Code:
public function o_get2($data) {
for ($i = 0; $i < count($data); $i++) {
$this->db->where('varyasyon_id', $data[$i]);
$result[] = $this->db->get('opsiyonlar')->result_array();
}
return $result;
}
IDs in Array
The data I want to bring from the database.
The data of each ID must be in different arrays.