我想獲取所有用戶數據,但我得到只有一個用戶的詳細信息,請幫我解決如何從數據庫中獲取所有用戶數據?
$conn = mysqli_connect("localhost", "root", "", "bitmining");
$sql6="SELECT username FROM users";
if($result = mysqli_query($conn, $sql6)){
while ($row=mysqli_fetch_array($result)){
//Hashrate Data Fetch
$investedusername = $row['username'];
$sql3="SELECT sum(hashrate_amount) as total FROM buyhashrate WHERE invested_username='$investedusername'";
$result = mysqli_query($conn, $sql3);
$row = mysqli_fetch_assoc($result);
//Total Value of Hashrate
echo $row['total'] . " GH/s";
echo "<br />";
}
$result->close();
}
使用'join',不需要2個查詢。 – chris85