Q:

Removes duplicate from table and add the value

I have a cart table which looks like but I want to remove the duplicate product and add the price
my sql query is this:
$query = mysql_query("select product.productname, product.price, order.quantity
from product inner join order on product.productid = order.productid");

and here is my php code
while($row = mysql_fetch_assoc($query))
{
    $total = $row['quantity']*$row['quantity'];
    echo '<tr>';
        echo '<td>'.$row['productname'].'</td>';
        echo '<td>'.$row['quantity'].'</td>';
        echo '<td>'.$row['price'].'</td>';
        echo '<td>'.$total.'</td>';
    echo '</tr>';
}

Product Name     Quantity      Unit Price       Total Price
Egg              12            6                72
Milk             2             30               60
Bread            5             5                25
Egg              3             6                18
Milk             5             30               150

I want to add the quantity and total price of the same product and the table should look like this
Product Name     Quantity      Unit Price       Total Price
Egg              15            6                90
Milk             7             30               210
Bread            5             5                25

How would I get the 2nd table result? should I change my query?

A:

Sounds like you are wanting to GROUP BY your "Product Name" column. Look into the GROUP BY clause and SUM() aggregation function in the MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
I think if you play around with SUM() and GROUP BY you'll get the hang of aggregating sets of data. 

