代码工作正常。但它只向我展示了最后5条记录。它有超过100条记录。我不知道发生了什么。不使用Ajax,它会显示所有记录。
实际上,我正在创建MLM软件。所以它有15个级别。因此,我在每个级别上显示Referal的记录。因此,在具有相同编码的第一级,所有事情都正常工作。表示显示第1级的所有记录。但是在第二级只显示我最后5个1级推荐的记录......所以在第1级,我有17个用户......
现在我注意到它在第二级只显示了一个用户Refrels。没有显示其他16个用户二级推荐。我是Ajax的新手。
所以请告诉我在哪里错了。是闭环问题吗?或其他任何事情。请建议我。谢谢..
第1页 - 来自数据库的Fething记录
<?php
/* Database connection start */
include_once ("db.php");
// Inialize session
session_start();
/* Database connection end */
if (!isset($_SESSION['username'])) {
print "
<script language='javascript'>
window.location = 'index.php';
</script>
";
}
// storing request (ie, get/post) global array to a variable
$requestData2= $_REQUEST;
$columns22 = array(
// datatable column index => database column name
0 =>'Id',
1 => 'username',
2=> 'fname'
);
//LEVEL 1 Fetching data
// getting total number records without any search
$totalref2 = 0;
$totalrefear2 = 0;
$frincome = 0;
$sql = "SELECT Id,fname,email,doj,active,username,mobile,pcktaken,activeamt,activegreen";
$sql.=" FROM newusers where referedby = '" . $_SESSION['username'] . "'";
$query=mysqli_query($con, $sql) or die("downline-grid-data2.php: get employees");
$totalData2 = mysqli_num_rows($query);
$totalFiltered22 = $totalData2; // when there is no search parameter then total number rows = total number filtered rows.
while ($row = mysqli_fetch_array($query)) {
$ac = "$row[active]";
$countusername = "$row[username]";
$sql22 = "SELECT Id,fname,email,doj,active,username,mobile,pcktaken,activeamt,activegreen";
$sql22.=" FROM newusers where referedby = '$countusername'";
if( !empty($requestData2['search']['value']) ) { // if there is a search parameter, $requestData2['search']['value'] contains search parameter
$sql22.=" AND ( Id LIKE '".$requestData2['search']['value']."%' ";
$sql22.=" OR username LIKE '".$requestData2['search']['value']."%' ";
$sql22.=" OR fname LIKE '".$requestData2['search']['value']."%' )";
}
$query22=mysqli_query($con, $sql22) or die("downline-grid-data2.php: get employees");
$totalFiltered22 = mysqli_num_rows($query22); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql22.=" ORDER BY ". $columns22[$requestData2['order'][0]['column']]." ".$requestData2['order'][0]['dir']." LIMIT ".$requestData2['start']." ,".$requestData2['length']." ";
/* $requestData2['order'][0]['column'] contains colmun index, $requestData2['order'][0]['dir'] contains order such as asc/desc */
$query22=mysqli_query($con, $sql22) or die("downline-grid-data2.php: get employees");
$amountlimit = 0;
$data2 = array();
while( $row22=mysqli_fetch_array($query22) ) { // preparing an array
$nestedData=array();
$ac2 = "$row22[active]";
$countusername2 = "$row22[username]";
$pcktook = "$row22[pcktaken]";
$mobile = "$row22[mobile]";
$activeamt2 = "$row22[activeamt]";
$activegreen = "$row22[activegreen]";
$doj2 = "$row[doj]";
$qu = "SELECT level2 FROM packages where id = $pcktook";
$re = mysqli_query($con, $qu);
while ($r = mysqli_fetch_array($re)) {
$ll2 = "$r[0]";
}
if ($ac2 == 1) {
$status2 = "success";
$totalrefear2 = $totalrefear2 + $activeamt1;
$amountlimit = $amountlimit + 1;
} else {
$status2 = "danger";
}
$totalref2 = $totalref2 + 1;
$nestedData[] = $countusername2;
$nestedData[] = $doj2;
$nestedData[] = $activeamt2;
$data2[] = $nestedData;
}
}
$json_data = array(
"draw" => intval( $requestData2['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( $totalData2 ), // total number of records
"recordsFiltered" => intval( $totalFiltered22 ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data2 // total data array
);
echo json_encode($json_data); // send data as json format
?>
第2页 - 按表ID进行的表和Ajax调用
<table class="table-fill" id="tblstudentslevel2">
<thead>
<tr>
<th class="text-left">Name</th>
<th class="text-left">Date</th>
<th class="text-left">Price</th>
</tr>
</thead>
<tbody class="table-hover">
</tbody>
</table>
<script>
/* $('#table1').DataTable({
ordering: false,
paging: true
});
*/
// Function added by USMAN, users-grid-data.php file is being used to fetch data from database. //
$(document).ready(function() {
var dataTable = $('#tblstudentslevel2').DataTable( {
"processing": true,
"serverSide": true,
"ajax":{
url :"downline-grid-data2.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#tblstudentslevel2").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
} );
} );
</script>
答案 0 :(得分:0)
有一些奇怪的事情,你正在使用带有内部AJAX调用的JQuery Datatable。在Serverside中,您尝试获取请求的数据,但我无法看到您在哪里发送数据...例如,如何获得$ _REQUEST ['start']而在您的AJAX中发送任何表单数据和任何数据打电话?
答案 1 :(得分:0)
看看pageLength选项并尝试一下:
var dataTable = $('#tblstudentslevel2').DataTable( {
"pageLength": 50,
"processing": true,
"serverSide": true,
"ajax":{
url :"downline-grid-data2.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#tblstudentslevel2").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
} );`
答案 2 :(得分:0)
喜欢这个
$sql = "select * from tableName order by id DESC limit 5"