通过jQuery将多维数组从控制器codeigniter传递到数据表

时间:2018-12-26 05:48:58

标签: php jquery ajax codeigniter datatables

我想将多维数组从控制器传递到dataTables。

我使用CodeIgniter和jquery dataTables。仅使用单个阵列就没有问题。但是使用 2d数组时,数据不会显示。

这是我的代码

控制器

function data_attend()
    {   
        $w          = $this->input->post("write");
        $d          = $this->input->post("delete");
        $lab_slct   = $this->input->post("lab_slct");
        $month_slct = $this->input->post("month_slct");
        $year_slct  = $this->input->post("year_slct");
        $draw       = intval($this->input->get("draw"));
        $start      = intval($this->input->get("start"));
        $length     = intval($this->input->get("length"));
        $data = array();
        $attend_test    = $this->m_human_capital->attend_test();

        $month = $this->m_general->month($month_slct)->row_array();
        $day_total  = $month['day_total'];
        $holiday    = $this->m_general->holiday()->result();
        $month      = $this->m_general->list_month()->result();
        $year       = $this->m_general->list_year()->result();
        $rows       = $this->m_human_capital->attendance($lab_slct, $keyword)->result_array();
        $a          = array();
        foreach ($rows as $row) {
            $a[$row['sn']][] = $row;
        }
        $rows2          = $a;
        $attendance_2   = $this->m_human_capital->attendance_2(array('ab.lab'=>$lab_slct))->result_array();
        $roaster        = $this->m_general->get_data('tb_roaster')->result_array();
        $attend_detail  = $this->m_general->get_data('tb_attend_detail')->result_array();
        $no=1;

        foreach ($attendance_2 as $attend_list) {
            foreach ($rows2 as $i){
                if (
                    $i = $attend_list['sn']) {
                    $a = $attend_list['name'];
                    $b = $attend_list['pst_desc'];
                    for($m=1; $m <= $day_total; $m++){
                        $tgl = date('Y-m-d', strtotime($year_slct.'-'.$month_slct.'-'.$m));
                        $detail_attend =  $this->m_human_capital->detail_attend($i,$tgl);
                        $detail_attend = $detail_attend->row_array();
                        $id = $detail_attend['at_id'];
                        $stat = $detail_attend['details'];
                        $note = $detail_attend['note'];
                        if ($write==1) {
                        $c = '<a href="javascript:edit_attend(\''.$id.'\',\'tb_attendance\',\'id\')"><span data-placement="left" data-original-title="'.$stat.'-'.$note.'" class="tooltips glyphicon '.$icon_details.'"></span></a>';
                        }else{
                        $c = '<span data-placement="left" data-original-title="'.$stat.'-'.$note.'" class="tooltips glyphicon '.$icon_details.'"></span>';
                        }
                    }
                    $d = array();
                    $d[] = $c;
                }

            $data[] = array (
                $no++,
                $a,
                $b,
                $d
            );
            }
        }

            $output = array(
                "draw"              => $draw,
                "recordsTotal"      => $attend_list->num_rows(),
                "recordsFiltered"   => $attend_list->num_rows(),
                "data"              => $data
            );
        echo json_encode($output);
    }

这是我的jquery脚本

//show data attendance new
$(document).ready(function() {
    $('#attendance_list').DataTable({
        "ajax": {
            "url": base_url+'human_capital/data_attend',
            "type": "POST",
            "data": {
                "write": $('#write').val(),
                "delete": $('#delete').val(),
                "lab_slct": $('#lab_slct').val(),
                "month_slct": $('#month_slct').val(),
                "year_slct": $('#year_slct').val()
            }
        }
    });
});

数据未显示,只是错误

  

最长执行时间超过300秒。

我需要做什么?

1 个答案:

答案 0 :(得分:0)

您可以通过将set_time_limit()设置为零来设置最大执行时间,这意味着无限制:

function data_attend()
    {   
        set_time_limit(0); //unlimited time execution
        $w          = $this->input->post("write");
        $d          = $this->input->post("delete");
        $lab_slct   = $this->input->post("lab_slct");
        //rest of your code