/*First SQL query:*/ $sql1 = "SELECT * FROM (select * from my_table WHERE id < $id ORDER BY id DESC LIMIT 1) AS x ORDER BY id LIMIT 1"; $result1 = mysqli_query($conn, $sql1); $resultCheck1 = mysqli_num_rows($result1); if ($resultCheck1 > 0) { while ($row1 = mysqli_fetch_assoc($result1)) { $sum1 = $row1['sum']; /*Second SQL query:*/ $sql2 = "SELECT * FROM (select * from my_table WHERE id = $id ORDER BY id DESC LIMIT 1) AS x ORDER BY id LIMIT 1"; $result2 = mysqli_query($conn, $sql2); $resultCheck2 = mysqli_num_rows($result2); if ($resultCheck2 > 0) { while ($row2 = mysqli_fetch_assoc($result2)) { $sum2 = $row2['sum']; /*Third SQL query:*/ $sql3 = "SELECT * FROM new_table"; /*Different table*/ $result3 = mysqli_query($conn, $sql3); $resultCheck3 = mysqli_num_rows($result3); if ($resultCheck3 > 0) { while ($row3 = mysqli_fetch_assoc($result3)) { $sum3 = $row3['sum']; echo $sum1 + $sum2 + $sum3; } } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)