Welcome Guest, Not a member yet? Register   Sign In
AJAX ARRAY
#1

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
[Image: s6OuIG.png]

The data I want to bring from the database.
[Image: IVwJGn.png]

The data of each ID must be in different arrays.
Reply


Messages In This Thread
AJAX ARRAY - by andwise - 05-30-2020, 04:08 PM
RE: AJAX ARRAY - by InsiteFX - 05-31-2020, 08:11 AM
RE: AJAX ARRAY - by andwise - 05-31-2020, 09:47 AM
RE: AJAX ARRAY - by InsiteFX - 06-01-2020, 03:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB