Arkadaşlar,
İhtiyaç gereği mssql ile bir proje kodluyorum.
Datatable ile sayfalama yapmam gerekiyor.
Mysql de bunu limit parametresiyle yapıyorduk.
Mssql de durum biraz farklı.
Offset, row_number denedim fakat söz diziliminde hata alıp duruyorum.
Bilgisi olan?
MSSQL + Codeigniter + Pagination Hakkında
3
●286
- 13-07-2016, 12:12:52MsSQL'de bunu direkt yapmanın yani mysql deki gibi limit ile yapmanın bir yolu yok, bunun için yanlış hatırlamıyorsam stored procedure kullanman gerekiyor.ercanakca adlı üyeden alıntı: mesajı görüntüle
Bir de şuraya bakabilirsin
http://stackoverflow.com/questions/1...-in-sql-server - 14-07-2016, 11:28:24Çözümü, belki ihtiyacı olanlar olur diye paylaşıyorum.
controller
public function getData($response = false){ $response = []; $qpost = $_POST["searchPhrase"]; $basla = intval($_REQUEST['current']); $uzunluk = intval($_REQUEST['rowCount'] * $basla); $basla = $basla != 1 ? (( $basla - 1 ) * 10 + 1) : 1; if($qpost == "") { $rows = $this->db->query("SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNum, * FROM yer) AS RowConstrainedResult WHERE RowNum >= $basla AND RowNum <= $uzunluk ORDER BY RowNum ")->result(); $total = $this->db->query("SELECT COUNT(id) AS total FROM yer")->row(); } else{ $rows = $this->db->query("SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNum, * FROM yer WHERE yer_adi LIKE '%".$qpost."%') AS RowConstrainedResult WHERE RowNum >= $basla AND RowNum <= $uzunluk ORDER BY RowNum ")->result(); $total = $this->db->query("SELECT COUNT(id) AS total FROM yer WHERE yer_adi LIKE '%".$qpost."%'")->row(); } if ($rows){ $response = array( 'current' => intval($_REQUEST['current']), 'rowCount' => $uzunluk, 'rows' => '', 'total' => $total->total, 'draw' => intval($_REQUEST['current']) ); foreach ($rows as $row) { $response['rows'][] = array( 'id' => $row->id, 'yer_adi' => $row->yer_adi, 'ilceID' => $row->ilceID, 'islem' => '<a href="" class="btn btn-primary btn-xs waves-effect">Düzenle</a> <a href="" class="btn btn-warning btn-xs waves-effect">Sil</a>' ); } } echo json_encode($response); }view
<div class="table-responsive"> <table id="grid-data" class="table table-condensed table-hover table-striped" data-toggle="bootgrid" data-ajax="true" data-url="getData"> <thead> <tr> <th data-column-id="id" data-type="numeric" data-sortable="false">ID</th> <th data-column-id="yer_adi" data-sortable="false">Yer / Mekan Adı</th> <th data-column-id="ilceID" data-sortable="false">İlçe</th> <th data-column-id="islem" data-sortable="false">İşlem</th> </tr> </thead> </table> </div>