dqz13288 2017-06-03 06:02
浏览 374
已采纳

如何将每日利率存入数据库

please anyone can help me to solve the problem, am new to php development field

am developing investment interest portal, am getting problem to store interest rate daily based into database, the actual problem is to store interest with user details, am using cron job to run function for every 24hours its working perfect but when i am login as user its storing that user's interest rate values only , other user not storing, i think am using session user logged details maybe this problem, please can anyone help me to store every users interest value with user details

    session_start();
    $_SESSION['sess_user'];
    $conn = mysqli_connect("localhost", "root", "", "bitmining");

    $investedusername = $_SESSION['sess_user']; 
    $sql3="SELECT sum(inv_amount) as total FROM buyinvest WHERE invested_username='$investedusername'";         

    $result = mysqli_query($conn, $sql3);           
    while($row = mysqli_fetch_assoc($result)){

        $investment = $row['total'];
        $days = 1;
        $interest_rate = (350/100/365) * $days ;
        $finalvalue = $interest_rate * $days;

    } 

    $date = "SELECT invest_timestamp FROM buyinvest ORDER BY invest_timestamp DESC LIMIT 1";
    $result = mysqli_query($conn, $date);
    $d_test = mysqli_fetch_assoc($result);

    $d_test2 = $d_test["invest_timestamp"];

    $timestamp = time();

    $investeduser = $_SESSION['sess_user'];
    $interestamount = $finalvalue;  
    $date_interest = date("y-m-d h:i:s");

    if ($d_test2  + 86400 == $timestamp){
        if ($conn){
                $sql3 = "INSERT INTO user_investments(invested_user, interest_amount, date_interest) VALUES('$investeduser','$interestamount','$date_interest')";
                if (mysqli_query($conn, $sql3))
                {
                    echo "Updated!";
                }
                else
                {
                    echo "There is an error.";
                }
            }
        }
        else {
        echo "Not yet!";
        } 

please anyone help me to solve above code

  • 写回答

1条回答 默认 最新

  • donglu1881 2017-06-03 10:48
    关注

    Something like this

    $sql = "SELECT * from table_name";
    $result = $conn->query($sql);
    if($result->num_rows > 0){
    
    while ($row = $result->fetch_assoc()) {
    
    $sql3="SELECT sum(inv_amount) as total FROM buyinvest WHERE invested_username='".$row['username']"'";
    // your code
    }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘