using Ajax on level 2 displaying only 5 users records,but with simple PHP working fine
using Ajax on level 2 displaying only 5 users records,but with simple PHP working fine
The code is Working Fine in Procedural PHP. But I used the same code in AJAX, But It's displaying me only 1 user Referral Records. It has more than 17 users on 1st LEVEL.But it's displaying me only 1 user Referrals on 2nd level. I don't know what's happening. without using Ajax it's displaying me all records.
Actually, I am creating MLM Software. So it has 15 Levels. So I'm Displaying Records on each level by Referal.
So on 1st level with the same coding, all things are working fine with AJAX. means displaying all 17 records of 1st level. But on 2nd level just displaying me only records of 1 user referral of 1st level...So at 1st level, I have 17 users and that 17 users having more than 100 users in their downline.but it's just displaying me one Referral downline users. Not displaying me rest of 16 users downline referrals on 2nd level.
so same thing Happening with other Levels.
In short - I have 15 levels, on 1st level All 17 users are displaying Fine. but on other 14 levels just displaying me 1 user Referrals.
The PHP code is fine because at this moment I am displaying members with PHP only. But I have more than 10,000 users so the page is loading too slow so that's why I want to use AJAX for fetching the data from the database.
Please see my code below and help me, because I am trying it from last 10 days. but nothing happened. Thanks.
1st page - downline-grid-data2.php
This code for LEVEL 2
<?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
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 =>'Id',
1 => 'username',
2=> 'fname'
);
//LEVEL 1 code
// getting total number records without any search
$totalref = 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");
while( $row=mysqli_fetch_array($query) ) {
$ac = "$row[active]";
$countusername = "$row[username]";
//LEVEL 2 Fetching data
$sql22 = "SELECT Id,fname,email,doj,active,username,mobile,pcktaken,activeamt,activegreen";
$sql22.=" FROM newusers where referedby = '$countusername'";
$query22=mysqli_query($con, $sql22) or die("downline-grid-data2.php: get employees");
$totalData22 = mysqli_num_rows($query22);
$totalFiltered22 = $totalData22; // when there is no search parameter then total number rows = total number filtered rows.
$sql22 = "SELECT Id,fname,email,doj,active,username,mobile,pcktaken,activeamt,activegreen";
$sql22.=" FROM newusers where referedby = '$countusername'";
if( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
$sql22.=" AND ( Id LIKE '".$requestData['search']['value']."%' ";
$sql22.=" OR username LIKE '".$requestData['search']['value']."%' ";
$sql22.=" OR fname LIKE '".$requestData['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 ". $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 */
$query22=mysqli_query($con, $sql22) or die("downline-grid-data2.php: get employees");
$data2 = array();
while( $row22=mysqli_fetch_array($query22) ) { // preparing an array
$nestedData=array();
$id = "$row22[Id]";
$username22 = "$row22[username]";
$fname = "$row22[fname]";
$ac = "$row22[active]";
$doj22 = "$row22[doj]";
$ear = "$row22[tamount]";
$ear = round($ear,2);
$top = "$row22[tamount]";
$top = round($top,2);
$ref = "$row22[referedby]";
$pck = "$row22[pcktaken]";
$lprofile = "$row22[launch]";
$rpin = "$row22[registrationpin]";
$activeamt22 = "$row22[activeamt]";
$activegreen = "$row22[activegreen]";
$sql1 = "SELECT Id FROM newusers WHERE referedby = '$username'";
$result2 = $con->query($sq1l);
$numrows = mysqli_num_rows($result2);
if ($numrows == 0) {
$number = 'No referer';
} elseif ($numrows == 1) {
$number = 'refered Once';
} else {
$number = 'refered ' . $numrows . ' times';
}
if ($ac == 1) {
$status = "success";
$totalrefear2 = $totalrefear2 + $activeamt22;
} else {
$status = "danger";
}
$sql = "SELECT fname,country,pcktaken FROM newusers WHERE username='" . $_SESSION['username'] . "'";
if ($result = mysqli_query($con, $sql)) {
/* fetch associative array */
while ($row = mysqli_fetch_row($result)) {
$coun = $row[1];
$pcktaken = $row[2];
$sql2 = "SELECT id,name,price FROM packages WHERE id=$pcktaken";
if ($result2 = mysqli_query($con, $sql2)) {
while ($row2 = mysqli_fetch_row($result2)) {
$pkname = $row2[0];
$pkprice = $row2[2];
}
}
}
}
if ($pkname == 31) {
$status = "you are Eligible for monthly salary";
$status2 = "Activated";
}elseif($pkname == 37){
$status = "Please upgrade your ID for monthly salary (24 Months)";
$status2 = "Activated";
}else{
$status = "Please upgrade your ID for monthly salary (24 Months)";
$status2 = "Not Activated";
}
$nestedData[] = $username22;
$nestedData[] = $doj22;
$nestedData[] = $activeamt22;
$nestedData[] = $status2;
$nestedData[] = $pkprice;
$data2[] = $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( $totalData22 ), // 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
<?php
>
```
?>
**2nd page - Table and Ajax call by Table ID - mydownline.php**
Name | Registration Date | Activation Amount | status | Package |
---|
```
Answers
Thanks for your question. As noted in the forum rules, please post a link to a test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Allan