dpspn60064 2015-01-22 19:06
浏览 7

管理员登录时如何更新所有用户?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私