Error pagination server side datatables php oci

Saya kesulitan ketika mengatur server side processing untuk datatables..

index.php

<table id="datatable-va" class="table table-striped table-bordered">
                                    <thead>
                                        <tr>
                                            <th class="tableanva">TANGGALAN</th>
                                            <th class="tableanva">EMPNAME</th>
                                            <th class="tableanva">TGJWB_AFD</th>
                                            <th class="tableanva">BLOCKCODE</th>
                                            <th class="tableanva">TPHCODE</th>
                                            <th class="tableanva">SEKSIDESC</th>
                                            <th class="tableanva">HEKTAR</th>
                                            <th class="tableanva">POKOKNYA</th>
                                            <th class="tableanva">TONASE</th>
                                            <th class="tableanva">BJR</th>
                                            <th class="tableanva">JJG_PANEN</th>
                                            <th class="tableanva">REALKGPANEN</th>
                                            <th class="tableanva">REALKGBROD</th>
                                            <th class="tableanva">VARIANCE</th>
                                            <th class="tableanva">VARIANCEPERCENT</th>
                                            <th class="tableanva">BUTIR_BRD</th>
                                            <th class="tableanva">PRUNNINGSONGGO</th>
                                    </thead>
</table>
$(document).ready(function() {

        $('#datatable-va').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"./fetchdata.php", // json datasource
                type: "POST"  // type of method  ,GET/POST/DELETE
            }
        });
});

fetchdata.php

<?php

session_start();

$username = "OPS_ADMIN";
$password = "BULET2KALI";

// Create connection to Oracle
ini_set ("display_errors", "0");
error_reporting(E_ALL);

$conn = oci_connect($username, $password, '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 103.121.213.170)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = BUMHO) (SID = BUMHO)))');

if (!$conn) {
	$m = oci_error();
	echo $m['message'], "\n";
	oci_free_statement($stid);
	oci_close($conn);
	exit;
}

$requestData = $columns = $totalRecords = $data = array();
$requestData= $_REQUEST;
$columns = array(
    0 =>'TANGGALAN',
    1 => 'EMPNAME',
    2 => 'TGJWB_AFD',
    3 => 'BLOCKCODE',
    4 => 'TPHCODE',
    5 => 'SEKSIDESC',
    6 => 'HEKTAR',
    7 => 'POKOKNYA',
    8 => 'TONASE',
    9 => 'BJR',
    10 => 'JJG_PANEN',
    11 => 'REALKGPANEN',
    12 => 'REALKGBROD',
    13 => 'VARIANCE',
    14 => 'VARIANCEPERCENT',
    15 => 'BUTIR_BRD',
    16 => 'PRUNNINGSONGGO'
);

$sql = "SELECT COUNT(*) AS C FROM EPMS_TRXI.t_variance_bkpops BK LEFT JOIN T_VA_USERAFD UA ON BK.DIVISIONCODE = UA.TGJWB_AFD WHERE UA.USERNAME = 'EKA SYAHPUTRA'";

$query=oci_parse($conn, $sql);
oci_execute($query);
oci_fetch_all($query, $result);
$numrows = $result['C'][0];
$totalFiltered = $numrows;

$vaquery = "SELECT *
        FROM (SELECT TO_CHAR(BK.WORKING_DATE, 'DD/MM/YYYY') AS TANGGALAN, BK.EMPNAME, UA.TGJWB_AFD, BK.BLOCKCODE, BK.TPHCODE, BK.SEKSIDESC, CAST(BK.HA_PROD AS DECIMAL(10,2)) AS HEKTAR,
        CAST(BK.POKOK_PROD AS DECIMAL(10,3)) AS POKOKNYA, CAST(BK.TONASE_PROD AS DECIMAL(10,3)) AS TONASE, CAST(BK.BJR_PROD AS DECIMAL(10,2)) AS BJR, BK.JJG_PANEN,
        CAST(BK.KG_PANEN AS DECIMAL(10,3)) AS REALKGPANEN, CAST(BK.KG_BRD AS DECIMAL(10,3)) AS REALKGBROD, CAST(BK.KG_PANEN - BK.TONASE_PROD AS DECIMAL(10,2)) AS VARIANCE,
        CAST((BK.KG_PANEN / BK.TONASE_PROD)*100 AS DECIMAL(10,2)) AS VARIANCEPERCENT, BK.BUTIR_BRD, BK.PRUNNINGSONGGO, BK.BKOPSID FROM EPMS_TRXI.t_variance_bkpops BK
        LEFT JOIN T_VA_USERAFD UA ON BK.DIVISIONCODE = UA.TGJWB_AFD WHERE UA.USERNAME = 'EKA SYAHPUTRA'";

if(isset($_POST['search']['value'])) {
	//----------------------------------------------------------------------------------
	$vaquery = $vaquery . " AND ( BK.TPHCODE LIKE '".$_POST['search']['value']."%' ";
	$vaquery = $vaquery . " OR BK.BLOCKCODE LIKE '".$_POST['search']['value']."%' ";
	$vaquery = $vaquery . " OR BK.EMPNAME LIKE '".$_POST['search']['value']."%' ";
	$vaquery = $vaquery . " OR BK.SEKSIDESC LIKE '".$_POST['search']['value']."%' ";
	$vaquery = $vaquery . " OR UA.TGJWB_AFD LIKE '".$_POST['search']['value']."%' ) ";
}
$vaquery = $vaquery . " ORDER BY ".$columns[$_POST['order'][0]['column']]." ".$_POST['order'][0]['dir'].") ";

$vaqueryassoc = ' ';
$vaqueryassoc = $vaqueryassoc . "WHERE ROWNUM >= ".intval($_POST['start'])." AND ROWNUM <= ".(intval($_POST['start']) + intval($_POST['length']))."";

$vatablenum = oci_parse($conn, $vaquery);
oci_execute($vatablenum);
$numpage = oci_fetch_all($vatablenum, $res);
$totalFiltered = $numpage;

$vatable = oci_parse($conn, $vaquery . $vaqueryassoc);
oci_execute($vatable);

$data = array();
while ($row = oci_fetch_array($vatable, OCI_BOTH)) {
    // $totalFiltered = $row['RNUM'];
    $data[] = $row;
}

$json_data = array(
 "draw"            => intval( $_POST['draw'] ),
 "recordsTotal"    => intval( $numrows ),
 "recordsFiltered" => intval( $totalFiltered ),
 "data"            => $data );
//----------------------------------------------------------------------------------
echo json_encode($json_data);
?>

Saya telah berhasil menampilkan data, filter data by search, sorting data dan mengatur berapa banyak entries yang ditampilkan dalam satu halaman. Tetapi saya mengalami error ketika ganti page datanya tidak muncul dengan tulisan "No matching records found"

avatar awalmlna
@awalmlna

2 Kontribusi 0 Poin

Diperbarui 3 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban