Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中while循环的乘法结果_Php_While Loop - Fatal编程技术网

php中while循环的乘法结果

php中while循环的乘法结果,php,while-loop,Php,While Loop,因此,我在php中有一个while循环,我正在从mysql数据库中提取每条记录,这很好,但我现在想做的是将列QTY的结果加在一起,得到一个总数,但我不确定如何将每个结果加在一起,因为每次while循环都会清除最后一个循环 例如,如果我有以下记录: ID QTY NAME 1 2 BOX1 2 54 BOX2 3 21 BOX6 当我在while循环中回显它们时,我得到的几乎和上面的一样。 我想做的是每次将数量添加到总数中,这样我就可以得到一个数量总数,并将

因此,我在php中有一个while循环,我正在从mysql数据库中提取每条记录,这很好,但我现在想做的是将列QTY的结果加在一起,得到一个总数,但我不确定如何将每个结果加在一起,因为每次while循环都会清除最后一个循环

例如,如果我有以下记录:

ID  QTY   NAME
1    2    BOX1
2    54   BOX2
3    21   BOX6
当我在while循环中回显它们时,我得到的几乎和上面的一样。 我想做的是每次将数量添加到总数中,这样我就可以得到一个数量总数,并将其用作$totalQTY

    $sql = <<<SQL
    SELECT * FROM `orders` WHERE `orderid` = '$view' AND `isline` = 'no'
    SQL;
    if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']');}
    while($row = $result->fetch_assoc()){
    echo '<h2>Order Id : '.$row['orderid'].'</h2>';
    echo '<p><strong>Customer Order Number : '.$row['customerordernumber'].'</strong></p>';
    echo '<p><strong>Order Date :</strong> '.date("d/m/Y H:i:s", strtotime($row["orderdatetime"])).'</p>';
    echo '<p><strong>Order Notes :</strong> '.$row['ordernotes'].'</p>';
    echo '<p><strong>Label Type :</strong> '.$row['labeltype'].'</p>';
    echo '<p><strong>Trolley Type :</strong> '.$row['trolleytype'].'</p>';
    echo '<p><strong>Deliver By :</strong> '.$row['deliverby'].'</p>';
    echo '<p><strong>Ordered Items : </strong></p>';
    }
$sql=fetch\u assoc()){
回显“订单Id:”.$row['orderid'].';
回显“客户订单号:”.$row['customerordernumber']”。;
回显“订单日期:”。日期(“d/m/Y H:i:s”,strottime($row[“orderdatetime”])。

”; 回显“订单注释:”.$row['ordernotes']。

”; 回显“标签类型:”。$row['labeltype']”。

; 回音“小车类型:”.$row[“小车类型”]。

”; echo“送货人:”.$row['deliveryby'.

”; 回显'订购的项目:

'; }
在循环外创建一个变量,并将其递增:

$count=0
while($row = $result->fetch_assoc()){
     $count+=$row['quantity'];
}
echo $count;

在循环外部创建一个变量,并将其递增:

$count=0
while($row = $result->fetch_assoc()){
     $count+=$row['quantity'];
}
echo $count;

在循环外部创建一个变量,并将其递增:

$count=0
while($row = $result->fetch_assoc()){
     $count+=$row['quantity'];
}
echo $count;

在循环外部创建一个变量,并将其递增:

$count=0
while($row = $result->fetch_assoc()){
     $count+=$row['quantity'];
}
echo $count;

按照你写的做:

$totalQTY = 0
while (....) {
   //...all your code....
   $totalQTY += $row['QTY']; // you didn't give the name of the column
}

按照你写的做:

$totalQTY = 0
while (....) {
   //...all your code....
   $totalQTY += $row['QTY']; // you didn't give the name of the column
}

按照你写的做:

$totalQTY = 0
while (....) {
   //...all your code....
   $totalQTY += $row['QTY']; // you didn't give the name of the column
}

按照你写的做:

$totalQTY = 0
while (....) {
   //...all your code....
   $totalQTY += $row['QTY']; // you didn't give the name of the column
}
$sql=fetch\u assoc()){
回显“订单Id:”.$row['orderid'].';
回显“客户订单号:”.$row['customerordernumber']”。;
回显“订单日期:”。日期(“d/m/Y H:i:s”,strottime($row[“orderdatetime”])。

”; 回显“订单注释:”.$row['ordernotes']。

”; 回显“标签类型:”。$row['labeltype']”。

; 回音“小车类型:”.$row[“小车类型”]。

”; echo“送货人:”.$row['deliveryby'.

”; 回显'订购的项目:

'; $totalqty+=intval($row['QTY???”);//必须更改字段值并添加此值 }
只需像上面那样添加一个计数器变量:)

$sql=fetch\u assoc(){ 回显“订单Id:”.$row['orderid'].'; 回显“客户订单号:”.$row['customerordernumber']”。; 回显“订单日期:”。日期(“d/m/Y H:i:s”,strottime($row[“orderdatetime”])。

”; 回显“订单注释:”.$row['ordernotes']。

”; 回显“标签类型:”。$row['labeltype']”。

; 回音“小车类型:”.$row[“小车类型”]。

”; echo“送货人:”.$row['deliveryby'.

”; 回显'订购的项目:

'; $totalqty+=intval($row['QTY???”);//必须更改字段值并添加此值 } 只需像上面那样添加一个计数器变量:)

$sql=fetch\u assoc(){ 回显“订单Id:”.$row['orderid'].'; 回显“客户订单号:”.$row['customerordernumber']”。; 回显“订单日期:”。日期(“d/m/Y H:i:s”,strottime($row[“orderdatetime”])。

”; 回显“订单注释:”.$row['ordernotes']。

”; 回显“标签类型:”。$row['labeltype']”。

; 回音“小车类型:”.$row[“小车类型”]。

”; echo“送货人:”.$row['deliveryby'.

”; 回显'订购的项目:

'; $totalqty+=intval($row['QTY???”);//必须更改字段值并添加此值 } 只需像上面那样添加一个计数器变量:)

$sql=fetch\u assoc(){ 回显“订单Id:”.$row['orderid'].'; 回显“客户订单号:”.$row['customerordernumber']”。; 回显“订单日期:”。日期(“d/m/Y H:i:s”,strottime($row[“orderdatetime”])。

”; 回显“订单注释:”.$row['ordernotes']。

”; 回显“标签类型:”。$row['labeltype']”。

; 回音“小车类型:”.$row[“小车类型”]。

”; echo“送货人:”.$row['deliveryby'.

”; 回显'订购的项目:

'; $totalqty+=intval($row['QTY???”);//必须更改字段值并添加此值 }

只需添加一个如上所述的计数器变量:)

在这个循环中,您在哪里执行乘法?我不是,这是问题所在,我不知道如何在while循环中进行乘法;而(…){$qty*=$row['qty'];}echo$qty可能你需要的是加法,而不是乘法?看到这么复杂的问题有这么多答案总是很高兴的。你在这个循环中的乘法是在哪里执行的?我不是,这是问题,我不知道如何在while循环中乘法。例如:
$qty=1;而(…){$qty*=$row['qty'];}echo$qty可能你需要的是加法,而不是乘法?看到这么复杂的问题有这么多答案总是很高兴的。你在这个循环中的乘法是在哪里执行的?我不是,这是问题,我不知道如何在while循环中乘法。例如:
$qty=1;而(…){$qty*=$row['qty'];}echo$qty可能你需要的是加法,而不是乘法?看到这么复杂的问题有这么多答案总是很高兴的。你在这个循环中的乘法是在哪里执行的?我不是,这是问题,我不知道如何在while循环中乘法。例如:
$qty=1;而(…){$qty*=$row['qty'];}echo$qty可能您需要的是加法,而不是乘法?对于这样一个复杂的问题,看到这么多答案总是一件令人高兴的事。$totalqty+=intval($row['qty']);}echo'订购的树数:。$totalqty'