I am preparing a MLM website in which I have to update all users single leg income, direct income and referral income when admin login. I was used same codes for individual updates I;e for each users.
For Eg: I am user and I am going to check my earnings, I have to login and check...So at the time of login I am updating all earnings of that user in database. So if user want to see updated earning,each time they have to singout and login again...simple. But in this case when user login...they passing a userid in session...through which I am synchronizing all incomes.
This is all about a particluar user...and may be their will be several users, and code for each as same.
But when we taking about admin, than??
They have to see earnings of all users in one page. I want help in that...I think I have to run all codes, single leg income, direct income and refral income in while loop..So all users must selected one by one and all incomes updating.
By bit confused ...please help...I thought I explain best of my knowledge...
Codes here:
Direct Income:
<?php
$userid=$_SESSION['userid'];
$sql="SELECT * from personal where userid='$userid'";
$query=mysqli_query($conn, $sql);
while($row=mysqli_fetch_array($query))
{
$id=$row['id'];
}
$sql="SELECT * from personal where id>'$id' limit 10";
$query=mysqli_query($conn,$sql);
$a=0;
while($row=mysqli_fetch_array($query))
{
$userid=$row['id'];
$username=$row['userid'];
$sponserid=$row['sponserid'];
$amount=$row['amount'];
if($row['amount']==2500)
{
$total1=2500;
}
else if($row['amount']==5000)
{
$total1=5000;
}
else if($row['amount']==10000)
{
$total1=10000;
}
else
{
$total1=0;
}
$i=array(0.05,0.02,0.01,0.005,0.0025,0.0025,0.0025,0.0025,0.0025,0.0025);
$total[]=$total1*$i[$a];
$a++;
$level_income = array_sum($total);
}
$qry="update personal set direct_income='$level_income' where userid='".$_SESSION['userid']."'";
mysqli_query($conn,$qry);
$_SESSION['level_income']=$level_income;
?>
Referral Income Code
<?php
include('head.php');
$query = "SELECT userid,amount FROM personal WHERE sponserid='$_SESSION[userid]'";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result) or die(mysqli_error($conn)))
{
$total[]=$row['amount'];
$income=array_sum($total);
$_SESSION['refral_income']=$income * 0.05;
$qry="update personal set refral_income='$_SESSION[refral_income]' where userid='".$_SESSION['userid']."'";
}
?>
Single Leg Income Code:
<?php
include('head.php');
$sql="SELECT * from personal where userid ='$_SESSION[userid]'";
$query=mysqli_query($conn, $sql);
while($row=mysqli_fetch_array($query))
{
$id=$row['id'];
}
$sql="SELECT * from personal where id>'$id'";
$query=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($query))
{
$userid=$row['id'];
$username=$row['userid'];
$fullname=$row['fullname'];
$sponserid=$row['sponserid'];
$amount=$row['amount'];
if($row['amount']==2500)
{
$total1=10;
}
else if($row['amount']==5000)
{
$total1=20;
}
else if($row['amount']==10000)
{
$total1=40;
}
else
{
$total1=0;
}
$total[]=$total1;
$single_leg_income=array_sum($total);
}
$_SESSION['income']=$single_leg_income;
$qry="update personal set single_leg_income='$single_leg_income' where userid='".$_SESSION['userid']."'";
mysqli_query($conn,$qry);
?>
I am using simple coding, and thinking to use PDO..But before that actually want to know...How I can do this in a single page for all users as a Admin.
Thanks.