I want to be able to show the number of items the client has and the total for them, and add the prices for each itemid and total price. I am not able to workout the logic for how to do that. So far i can show all the items a client has but some of the items are repeated.

```
$clientid = 24;

$query = "SELECT items.itemid, prices.priceid FROM items 
JOIN prices ON items.itemid = prices.itemid 
WHERE items.clientid = '$clientid'";

$result =  $db_connect -> query($query);
$row_cnt = $result -> num_rows; 

echo $joinrow_cnt."<br/><br/><br/>";

while($assocresult = mysqli_fetch_assoc($result)){
    $price = $assocresult['priceid'];
    $item = $assocresult['itemid'];
    $realprice = ($price/100)*80;        //after 80% discount
    echo "ItemId: ".$item." Price : " .$price." real price: " .$realprice."<br/>";  
}

```

So far i get : 

```
ItemId: 1 Price : 100 real price: 80
ItemId: 3 Price : 25 real price: 20
ItemId: 1 Price : 100 real price: 80
ItemId: 5 Price : 200 real price: 160
ItemId: 3 Price : 25 real price: 20
ItemId: 1 Price : 100 real price: 80

```

See how ItemId 1 and 3 are repeated. There are many such rows where the item ids are repeated.

I want the output to be like : 

```
ItemId: 1x3 Price: 100 real price = 80x3=240
ItemId: 3x2 Price: 25 real price = 20x2=50
ItemId: 5   Price: 200 real price: 160 //since this item is listed only once.

```

Please help. Many thanks!!