0

堆栈溢出,

$resultpaid = $mysqli->query($paidquery);
while ($row=$resultpaid->fetch_array()) 
{
  print $row['paid'] .'<br />';
}

我意识到这应该很简单,不幸的是,我并不精通 PHP。我试图从这个while循环中获取结果集并将它们分配给变量。基本上现在它找到两行,都是整数值。因此,当它迭代时,它会打印出 250 和 260。我试图弄清楚是否有办法为每一行分配一个变量,以便将整数相加,或者在某个点单独引用它们。

4

2 回答 2

0

您可能想用数据构建一个数组。

$myArray = array();
$resultpaid = $mysqli->query($paidquery);
while ($row=$resultpaid->fetch_array()) 
{
    $myArray[$row['id']] = $row['paid'];
    print $row['paid'] .'<br />';
}
// $myArray here is filled up with your data
于 2012-11-08T14:17:47.227 回答
0

当然,试试这个,

 $total = 0;
 $resultpaid = $mysqli->query($paidquery);
 while ($row=$resultpaid->fetch_array()) 
 {
  $arr[] = $row['paid']; //gets individual values in an array
  $total += $row['paid']; //adds them up
  print $row['paid'] .'<br />';
 }
于 2012-11-08T14:21:13.800 回答