0

现在拔头发

我有一个查询,计算数组中所有相关的 $price 值基本上初始查询检查表中已完成但未开票的作业第二个查询(在初始查询循环内)获取所有需要加起来的项目(这些值在另一个表 (workshop-items) 中找到并根据 $item 数组值进行检查

总数正在计算中,我认为这与 $total 的放置位置有关,因为它加起来了所有返回的总数,而不是单个行的总数

下面的代码

<ul class="list-group">
<?php 
    $uninvoicedq = mysqli_query($con,"SELECT * FROM `workshop-jobs` WHERE completed = '1' AND invoiced = '0' AND wscid !='0' ORDER BY workstartdate ASC");
    $uninvoiced = mysqli_fetch_assoc($uninvoicedq);
    if($uninvoiced) {
        do { 
            // User Query
            $wscid = $uninvoiced['wscid'];
            $userq = mysqli_query($cona,"SELECT * FROM `users` WHERE userid = '$wscid'");
            $user = mysqli_fetch_assoc($userq);
            $wtbdq = mysqli_query($con,"SELECT * FROM `workshop-jobs` WHERE wsjid = '$uninvoiced[wsjid]'");
            $wtbdr = mysqli_fetch_assoc($wtbdq);
                do {
                    $wtbd = explode(":",$wtbdr['worktobedone']);
                    foreach($wtbd as $item) 
                    {
                        $priceq = mysqli_query($con,"SELECT * FROM `workshop-items` WHERE wsiid = '$item'");
                        $pricer = mysqli_fetch_assoc($priceq);

                        $price[] = $pricer['incvat'];
                        $items[] = $pricer['description'];
                        //echo $item.' - '. $pricer['incvat'].'<br>';
                    }

                    $total = array_sum($price);
                } while($wtbdr = mysqli_fetch_assoc($wtbdq));
?>
    <li class="list-group-item text-right" style="border:none;" title="<?php echo $itemview;?>"><span class="badge pull-left" style="background-color:#F00;">Not Invoiced</span><?php echo '&pound;'.$total.' - '; echo $user['forename'].' '.$user['surname'].' - ' .$uninvoiced['summary'];?> </li>
<?


                $itemList = implode(":",$items);
                $itemview = str_replace(":","\n",$itemList);
?>

<?          } while($uninvoiced = mysqli_fetch_assoc($uninvoicedq));
        } else { 
            echo "No Jobs Waiting To Invoiced";
        }
?>
        </ul>
4

1 回答 1

1

如果您的意思是 的每一行do while应该是不同的总计,那么,当do开始时,设置$price = [];or$price = array();或 to null,因为如果您的最终价格是针对的每个查询do while而不是为了洞,照我说的做。

记住这样做$total +=,而不是$total =因为你会覆盖你在主循环之外使用的变量,所以你会得到一个错误的总数。

于 2017-05-17T14:52:28.410 回答