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!";
}
请有人帮我解决上面的代码
答案 0 :(得分:0)
像这样的东西
$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
}
}