PHP删除重复的值,并显示一个

时间:2018-07-11 05:37:50

标签: php mysql-workbench

<?php
include ("../pos/db_config/db_config.php");
include ("../pos/functions/select.php");


$i = 0;
$sql = topsalep($idCompany);
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
    $end_sale_date = $row["end_sale_date"];
    $name = $row["name"];
    $tot_s = $row["tot_price"];
    $qc = $row["sales_item_qty"];



    $proResult[$i][0] = $name;
    $proResult[$i][1] = $end_sale_date;
    $proResult[$i][2] = $tot_s;
    $proResult[$i][3]  = $qc;
     $i++;
}


//$name = $proResult[0][0];
//echo "$name";

for ($i = 0; $i < $result->num_rows; $i++) {

    $count = 0;
    $name = $proResult[$i][0];
    $date = $proResult[$i][1];
    $price = $proResult[$i][2];
    $qct = $proResult[$i][3];
    $totalPrice = 0;



    for ($j = 0; $j < $result->num_rows; $j++) {
        if ($proResult[$j][1] == $date && $proResult[$j][0] == $name) {


            $x = $proResult[$j][2];

            $count++;
            $totalPrice+=$x;
        }



    }

    $name = $proResult[$i][0];
    $date = $proResult[$i][1];
    $price = $proResult[$i][2];

    for ($k = 0; $k < $count; $k++){
     if($proResult[$k][1] == $date && $proResult[$k][0] == $name)
     {

     }
    }

    echo "Name : $name  <br>";
    echo "End Date : $date : Count $count : total = $totalPrice <br><br>";    
    ?>

在此代码中,我显示了最近5天产品虎钳的总价值。一天可能发生相同的销售,但存在不同数量的产品。然后,最后我计算了一个产品明智的总销售价值。但是问题是重复的。     在我的联接查询中,我使用了 distinct ,但是当重复的值仅显示一个值时,我想显示我的PHP代码。

enter image description here

enter image description here

0 个答案:

没有答案