Php 从特定行获取求和值
我有这个:Php 从特定行获取求和值,php,mysql,rows,Php,Mysql,Rows,我有这个: $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;
$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));
$result=mysqli\u query($mysqli,“从“.MYSQLBTCTABLE”中选择余额。“其中地址=”。$\u POST['address']。“'LIMIT 1”);
while($row=mysqli\u fetch\u assoc($result)){
$balance=$row['balance'];
echo“您当前的余额为:
”;
printf(“%0.8f”)(余额/100000000美元);
但它只得到我需要的最后一个值,我需要从该地址找到所有余额,并将它们合计,以供$balance
使用
$balance += $row['balance'];
使用灰色:
$result = mysqli_query($mysqli, "SELECT sum(balance) FROM " . MYSQLBTCTABLE . " WHERE address='" . $_POST['address'] . "' GROUP BY address");
从查询中删除
限制
,然后添加总和
$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));
$result=mysqli\u query($mysqli,“选择SUM(balance)作为“.MYSQLBTCTABLE.”中的totalBalance.“其中address=”)“$\u POST['address']”);
$row=mysqli\u fetch\u assoc($result);
$balance=$row['totalBalance'];
echo“您当前的余额为:
”;
printf(“%0.8f”)(余额/100000000美元);
首先,取而代之的是:
$balance = $row['balance'];
使用:
此外,摆脱“限制1”约束删除限制1并进行求和
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));
$result=mysqli\u查询($mysqli,“从“.MYSQLBTCTABLE”中选择余额。”其中
地址=“$”邮政[“地址”]。“””;
美元余额=0;
while($row=mysqli\u fetch\u assoc($result)){
$balance+=$row['balance'];
echo“您当前的余额为:
”;
printf(“%0.8f”)(余额/100000000美元);
好吧,这是答案的一半哦,是的,最后有一个“限制1”应该被删除。你在哪里结束循环?我已经添加了总和,我已经删除了限制,我添加了+=它正在工作,除了那个讨厌的错误警告:mysqli\u fetch\u assoc()期望参数1是mysqli_result,布尔值在…中给出。当参数达到1000时,它只会计数到999,然后重新开始计数
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));