我有这个:
$result = mysqli_query($mysqli, "SELECT balance FROM " . MYSQLBTCTABLE . " WHERE address='" . $_POST['address'] . "' LIMIT 1");
while($row = mysqli_fetch_assoc($result)) {
$balance = $row['balance'];
echo "<font style='font-weight:bold;'>Your current balance is: </font><br/>";
printf("%0.8f", ($balance / 100000000));
但它只获取我需要的最后一个值来查找该地址的所有余额,并将$balance
的总和相加。
答案 0 :(得分:0)
使用
$balance += $row['balance'];
答案 1 :(得分:0)
使用agregation:
$result = mysqli_query($mysqli, "SELECT sum(balance) FROM " . MYSQLBTCTABLE . " WHERE address='" . $_POST['address'] . "' GROUP BY address");
答案 2 :(得分:0)
从查询中删除LIMIT
并添加SUM
$result = mysqli_query($mysqli, "SELECT SUM(balance) as totalBalance FROM " . MYSQLBTCTABLE . " WHERE address='" . $_POST['address'] . "'");
$row = mysqli_fetch_assoc($result);
$balance = $row['totalBalance'];
echo "<font style='font-weight:bold;'>Your current balance is: </font><br/>";
printf("%0.8f", ($balance / 100000000));
答案 3 :(得分:0)
首先,改为:
$balance = $row['balance'];
使用:
$balance += $row['balance'];
此外,摆脱“LIMIT 1”约束
答案 4 :(得分:0)
Remove limit 1 and do the sum
$result = mysqli_query($mysqli, "SELECT balance FROM " . MYSQLBTCTABLE . " WHERE
address='" . $_POST['address'] . "' ");
$balance = 0;
while($row = mysqli_fetch_assoc($result)) {
$balance += $row['balance'];
echo "<font style='font-weight:bold;'>Your current balance is: </font><br/>";
printf("%0.8f", ($balance / 100000000));