Ramazan
Regular Member
- Aug 19, 2018
- 433
- 308
I'm trying to get the data in order but can't because my array in backlink-l.php file and my main file is backlink-list.php I can list all data but its seems random how can I get selected data for my table?
used this website for codes: https://learninfinity.info/server-side-processing-datatable-with-php-and-mysql/
used this website for codes: https://learninfinity.info/server-side-processing-datatable-with-php-and-mysql/
PHP:
<?php
require_once("../own/connect/mysqli.php");
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
$columns = array(
0 => 'backlink_title',
1 => 'backlink_dapa',
2 => 'backlink_spamscore',
3 => 'backlink_age',
4 => 'backlink_type',
5 => 'backlink_offpagescore',
6 => 'backlink_link',
7 => 'backlink_steps',
8 => 'backlink_premium'
);
$where_condition = $sqlTot = $sqlRec = "";
if( !empty($params['search']['value']) ) {
$where_condition .= " WHERE ";
$where_condition .= " ( backlink_id LIKE '%".$params['search']['value']."%' ";
$where_condition .= " OR backlink_dapa LIKE '%".$params['search']['value']."%' )";
}
$sql_query = " SELECT * FROM backlink ";
$sqlTot .= $sql_query;
$sqlRec .= $sql_query;
if(isset($where_condition) && $where_condition != '') {
$sqlTot .= $where_condition;
$sqlRec .= $where_condition;
}
$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";
$queryTot = mysqli_query($con, $sqlTot) or die("Database Error:". mysqli_error($con));
$totalRecords = mysqli_num_rows($queryTot);
$queryRecords = mysqli_query($con, $sqlRec) or die("Error to Get the Post details.");
while( $row = mysqli_fetch_row($queryRecords) ) {
$data[] = $row;
}
$json_data = array(
"draw" => intval( $params['draw'] ),
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval($totalRecords),
"data" => $data
);
echo json_encode($json_data);
?>
HTML:
<table id="post_list" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>Title</th>
<th>Da/Pa</th>
</tr>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>