2
<?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>";    
    ?>

In this code I showed Last 5 days product vise total value. A one day can happen same sale id there different quantity of products. Then finally I calculated the one product wise total sale value. But problem is duplicate it. In my join query I used distinct But I want show my PHP code when duplicated values only show one value.

enter image description here

enter image description here

Paweł Fus
  • 44,795
  • 3
  • 61
  • 77
chamila
  • 47
  • 1
  • 7
  • You can use array_unique() function at PHP level – Sambhaji Katrajkar Jul 11 '18 at 05:41
  • Possible duplicate of [How to remove duplicate values from an array in PHP](https://stackoverflow.com/questions/307650/how-to-remove-duplicate-values-from-an-array-in-php) – Gufran Hasan Jul 11 '18 at 05:43
  • @SambhajiKatrajkar can you tell me the where is the place I want use – chamila Jul 11 '18 at 05:43
  • Can you please show which data you are getting from database and how it should be look like? – Sambhaji Katrajkar Jul 11 '18 at 05:44
  • select distinct si.sale_idsale,si.sales_item_qty,s.end_sale_date,p.idproduct,p.name,whp.unit_price,(whp.unit_price * si.sales_item_qty) as tot_price from sales_item si INner join sale s on si.sale_idsale = s.idsale inner join product p on si.product_idproduct = p.idproduct inner join warehouse_has_product whp on whp.idproduct = p.idproduct where s.end_sale_date >= DATE_SUB(CURDATE(), INTERVAL 5 DAY) AND whp.idcompany = 1 group by si.sale_idsale,si.sales_item_qty,s.end_sale_date,p.name,whp.unit_price – chamila Jul 11 '18 at 05:57
  • How is MySQL Workbench related to the question? – axiac Jul 11 '18 at 12:41
  • I'm not sure I fully understand the question, but you might want select SUM(sales_item_qty), and not group by it. In that case, SELECT DISTINCT is also not what you want. Also grouping by name und unit_price is suspicious. – Karsten Koop Jul 11 '18 at 13:08

0 Answers0