从db获取数据并显示在codeigniter和jquery中

时间:2017-10-02 11:09:20

标签: php jquery codeigniter-3

在我的控制器中:

public function viewOrders() {
        $territoryId = $this->input->post('tid');
        $dateStart = $this->input->post('sdate');
        $dateEnd = $this->input->post('edate');

        $data = array(
            'TERRITORY_ID' => $territoryId,
            'ORDER_DATE' => $dateStart,
            'EXP_COLL_DATE' => $dateEnd
        );

        $this->order->viewOrder($data);
    }

在我的模型中:

public function viewOrder($data) {
        return $this->db->select('ORDER_ID,ORDER_DATE,EXP_COLL_DATE,STATUS')
                        ->from('ORDER_HEADER')
                        ->join('ORDER_DETAILS', 'ORDER_HEADER.TERRITORY_ID=ORDER_DETAILS.TERRITORY_ID', 'INNER')
                        ->where($data);

    }

在页脚(视图)中:

function viewOrders() {
        var dateStart = $('#dateStart').val();
        var dateEnd = $('#dateEnd').val();
        var territories = $('#territory').val();

        $.post("<?php echo base_url(); ?>/index.php/Orders/viewOrders", {tid: territories, sdate: dateStart, edate: dateEnd}).done(function (data) {
            alert(data);

        });
    }

1 个答案:

答案 0 :(得分:0)

您错过了 - $ query = $ this-&gt; db-&gt; get(); get array here $ data = $ query-&gt; result_array();

并返回$ data