Answer the question
In order to leave comments, you need to log in
How to splice data in php array?
The mysql database has a table s_orders, it contains the data I need, this is the customer name (name) and the order amount (total_price).
How to add the same customers (name) and order amount (total_price ) so that not all orders are displayed, but only the customer's name and the total amount of all his orders?
I take out clients with such a request
$addrs=array();
$result=mysql_query("SELECT name,address,phone,delivery_id,total_price FROM s_orders WHERE status = '2' AND paid = '1' ORDER BY total_price");
$n=mysql_num_rows($result);
for($i=0;$i<$n;$i++) {
array_push($addrs, mysql_result($result,$i,"name"));
array_push($addrs, mysql_result($result,$i,"total_price"));
}
mysql_close($db);
echo implode("", $addrs);
Answer the question
In order to leave comments, you need to log in
I changed it like this, but it displays only one client and the amount of only one order and not for all (
$result=mysql_query("SELECT name,address,phone,delivery_id,total_price, sum(total_price) FROM s_orders WHERE status = '2' AND paid = '1' AND name != 'Тест' ORDER BY name");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question