在codeignitier中使用限制的错误

时间:2016-12-22 03:07:51

标签: codeigniter

我的错误问题是什么?

function get_datatables1()
{       
    $tSQL = "select a.Kode, c.nama as Ruangan, d.nama as Kelas, b.nama as Kamar, a.jumlah as JumlahTT, a.sisa as SisaTT, a.Tarif, a.Deskripsi, a.Gambar from TMTrfTindakan a inner join TMTrfLayanan b on a.kodelayanan = b.kode inner join TMTrfKelompok c on b.kodekelompok = c.kode inner join TMTrfKelas d on a.kodekelas = d.kode where c.KodeKlasifikasi = 2";
    $query = $this->db->query($tSQL);
    //  $this->kamar->count_filtered1()
    if($_POST['length'] != -1)
        $this->db->query($tSQL)->limit($_POST['length'], $_POST['start']);
    $query = $this->db->query($tSQL);
    return $query->result();
}

错误说:

  

严重性:错误

     

消息:调用未定义的方法CI_DB_sqlsrv_result :: limit()

1 个答案:

答案 0 :(得分:0)

您的查询将在执行$this->db->query($tSQL)时运行。您无法为查询结果添加限制。

尝试使用codeigniter active record

function get_datatables1()
{  
    $this->db->select('a.Kode, c.nama as Ruangan, d.nama as Kelas, b.nama as Kamar, a.jumlah as JumlahTT, a.sisa as SisaTT, a.Tarif, a.Deskripsi, a.Gambar');
    $this->db->from('TMTrfTindakan a');
    $this->db->join('TMTrfLayanan b', 'a.kodelayanan = b.kode', 'inner');
    $this->db->join('TMTrfKelompok c', ' b.kodekelompok = c.kode', 'inner');
    $this->db->join('TMTrfKelas d', 'a.kodekelas = d.kode', 'inner');
    $this->db->where('c.KodeKlasifikasi', 2); 
    if($_POST['length'] != -1)
        $this->db->limit($_POST['length'], $_POST['start']);

    $query = $this->db->get();
    return $query->result();
}

此外,您可以在没有活动记录的情况下执行此操作

function get_datatables1()
{       
    $tSQL = "select a.Kode, c.nama as Ruangan, d.nama as Kelas, b.nama as Kamar, a.jumlah as JumlahTT, a.sisa as SisaTT, a.Tarif, a.Deskripsi, a.Gambar from TMTrfTindakan a inner join TMTrfLayanan b on a.kodelayanan = b.kode inner join TMTrfKelompok c on b.kodekelompok = c.kode inner join TMTrfKelas d on a.kodekelas = d.kode where c.KodeKlasifikasi = 2";

    if($_POST['length'] != -1)
        $tSQL .= 'limit ' . $_POST['length'] . ' offset ' . $_POST['start'];

    $query = $this->db->query($tSQL);
    return $query->result();
}