использование переменной сессии внутри серверного скрипта datatable - PullRequest
0 голосов
/ 10 апреля 2020

Ниже приведен мой серверный скрипт данных. Я хочу передать переменную в моем запросе sql, используя переменную SESSION.

 <?php

 /* Database connection start */
 require 'connections/conn_loglib.php';

 /* Database connection end */


// storing  request (ie, get/post) global array to a variable  
$requestData= $_REQUEST;


$columns = array( 
// datatable column index  => database column name
0 =>'well', 
1 => 'jobname',
2 => 'actualjobdate',
3 => 'rushdatastatus',
4 => 'corrected',
5 => 'printed',
6 => 'printedby',
7 => 'transtlsign',
8 => 'dispatched',
9 => 'epinet',
10=> 'loaddt',
11 =>'user',
12 =>'modified_timestamp'
 );

 // getting total number records without any search
 $sql = "SELECT well, jobname, actualjobdate, rushdatastatus, corrected, printed, printedby, transtlsign, dispatched, epinet, loaddt, user, modified_timestamp ";
 $sql.=" FROM jobs_history";
 $query=mysqli_query($con, $sql) or die("jobshistory.php: get employees");
 $totalData = mysqli_num_rows($query);
 $totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.


 $sql = "SELECT well, jobname, actualjobdate, rushdatastatus, corrected, printed, printedby, transtlsign, dispatched, epinet, loaddt, user, modified_timestamp ";
 $sql.=" FROM jobs_history WHERE 1=1";
 if( !empty($requestData['search']['value']) ) {   // if there is a search parameter, 
$requestData['search']['value'] contains search parameter
$sql.=" AND ( well LIKE '".$requestData['search']['value']."%' ";    
$sql.=" OR jobname LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR actualjobdate LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR rushdatastatus LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR corrected LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR printed LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR printedby LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR transtlsign LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR dispatched LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR epinet LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR loaddt LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR user LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR modified_timestamp LIKE '".$requestData['search']['value']."%' )";


}
$query=mysqli_query($con, $sql) or die("jobshistory.php: get employees");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. 
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   "; 
 /* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc , $requestData['start'] contains start row number ,$requestData['length'] contains limit length. */   
 $query=mysqli_query($con, $sql) or die("jobshistory.php: get employees");


$data = array();
while( $row=mysqli_fetch_array($query) ) {  // preparing an array
$nestedData=array(); 

$nestedData[] = $row["well"];
$nestedData[] = $row["jobname"];
$nestedData[] = $row["actualjobdate"];
$nestedData[] = $row["rushdatastatus"];
$nestedData[] = $row["corrected"];
$nestedData[] = $row["printed"];
$nestedData[] = $row["printedby"];
$nestedData[] = $row["transtlsign"];
$nestedData[] = $row["dispatched"];
$nestedData[] = $row["epinet"];
$nestedData[] = $row["loaddt"];
$nestedData[] = $row["user"];
$nestedData[] = $row["modified_timestamp"];


$data[] = $nestedData;
}

$json_data = array(
        "draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. 
        "recordsTotal"    => intval( $totalData ),  // total number of records
        "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
        "data"            => $data   // total data array
        );

echo json_encode($json_data);  // send data as json format

?>

Я пробовал таким образом, но таблица данных не загружается.

<?php
/* Database connection start */
require 'connections/conn_loglib.php';

/* Database connection end */


// storing  request (ie, get/post) global array to a variable  
 $requestData= $_REQUEST;


$columns = array( 
// datatable column index  => database column name
0 =>'well', 
1 => 'jobname',
2 => 'actualjobdate',
3 => 'rushdatastatus',
4 => 'corrected',
5 => 'printed',
6 => 'printedby',
7 => 'transtlsign',
8 => 'dispatched',
9 => 'epinet',
10=> 'loaddt',
11 =>'user',
12 =>'modified_timestamp'
);

$k='$_SESSION["well"]'


// getting total number records without any search
$sql = "SELECT well, jobname, actualjobdate, rushdatastatus, corrected, printed, printedby, transtlsign, dispatched, epinet, loaddt, user, modified_timestamp ";
$sql.=" FROM jobs_history WHERE well='". $k."'";
$query=mysqli_query($con, $sql) or die("jobshistory.php: get employees");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.


$sql = "SELECT well, jobname, actualjobdate, rushdatastatus, corrected, printed, printedby, transtlsign, dispatched, epinet, loaddt, user, modified_timestamp ";
$sql.=" FROM jobs_history WHERE well='".$k."'";
if( !empty($requestData['search']['value']) ) {   // if there is a search parameter, 
$requestData['search']['value'] contains search parameter
$sql.=" AND ( well LIKE '".$requestData['search']['value']."%' ";    
$sql.=" OR jobname LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR actualjobdate LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR rushdatastatus LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR corrected LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR printed LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR printedby LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR transtlsign LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR dispatched LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR epinet LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR loaddt LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR user LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR modified_timestamp LIKE '".$requestData['search']['value']."%' )";


}
$query=mysqli_query($con, $sql) or die("jobshistory.php: get employees");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. 
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   "; 
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc , $requestData['start'] contains start row number ,$requestData['length'] contains limit length. */    
$query=mysqli_query($con, $sql) or die("jobshistory.php: get employees");


$data = array();
while( $row=mysqli_fetch_array($query) ) {  // preparing an array
$nestedData=array(); 

$nestedData[] = $row["well"];
$nestedData[] = $row["jobname"];
$nestedData[] = $row["actualjobdate"];
$nestedData[] = $row["rushdatastatus"];
$nestedData[] = $row["corrected"];
$nestedData[] = $row["printed"];
$nestedData[] = $row["printedby"];
$nestedData[] = $row["transtlsign"];
$nestedData[] = $row["dispatched"];
$nestedData[] = $row["epinet"];
$nestedData[] = $row["loaddt"];
$nestedData[] = $row["user"];
$nestedData[] = $row["modified_timestamp"];


$data[] = $nestedData;
}

$json_data = array(
        "draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. 
        "recordsTotal"    => intval( $totalData ),  // total number of records
        "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
        "data"            => $data   // total data array
        );

 echo json_encode($json_data);  // send data as json format

 ?>

Теперь, наконец, если я не могу использовать переменную SESSIOn в серверном скрипте, любой другой альтернативный способ передачи переменной в серверный скрипт при загрузке таблицы данных ...?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...