[HELP] Datatables Selecting array data problem

Ramazan

Regular Member
Joined
Aug 19, 2018
Messages
433
Reaction score
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/
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>
 
Something like

Code:
<table id="post_list" class="display" width="100%" cellspacing="0">
            <thead>
                <tr>
                <th>Title</th>
                <th>Da/Pa</th>
             
                </tr>
            </thead>
            <tbody>
<?php
foreach ($data as $row) {
echo '<tr><td>' . $row[0] . '</td><td>' . $row[1] . '</td></tr>';
}
?>
           
         
            </tr>
            </tbody>
         
        </table>

I misread the question. Take a look here https://datatables.net/examples/ajax/custom_data_flat.html
 
Last edited:
Something like

Code:
<table id="post_list" class="display" width="100%" cellspacing="0">
            <thead>
                <tr>
                <th>Title</th>
                <th>Da/Pa</th>
             
                </tr>
            </thead>
            <tbody>
<?php
foreach ($data as $row) {
echo '<tr><td>' . $row[0] . '</td><td>' . $row[1] . '</td></tr>';
}
?>
           
         
            </tr>
            </tbody>
         
        </table>
Thanks for the answer I have a problem with $data thing because I can't include my array page. It gives an error.
 
Back
Top