使用CodeIgniter中的AJAX从数据库中获取数据

时间:2018-07-12 04:53:16

标签: ajax codeigniter

当我们从数据库中获取json数组时,此代码在codeigniter中不起作用。 我们如何使用ajax

从数据库中获取数据
select to_char(hire_date,'month'),count(employee_id)
from employees
group by to_char(hire_date,'month')


TO_CHAR(HIRE_DATE,'MONTH')           COUNT(EMPLOYEE_ID)
------------------------------------ ------------------
march                                                17
january                                              13
february                                             13
june                                                 11
august                                                9
december                                              7
july                                                  7
april                                                 7
october                                               6
may                                                   6
september                                             5
november                                              5

1 个答案:

答案 0 :(得分:1)

这就是你所需要的

1.Controller:

var csv = "118.0000000000,102.6666666666,110.6666666666,97.5000000000,82.5000000000,86.6666666666";
var csv35 = substr(csv, 0, 35);
var nums = csv35.split(",");
nums.length--;

2。型号:

class Ajax extends CI_Controller
{
    public function Users($id)
    {
        $this->load->model('User_mdel');
        echo json_encode($this->User_mdel->list());
    }
}

3。查看

class User_mdel extends CI_Model
{
    public function list()
    {
        return $this->db->get('users')->result();
    }
}

和END