How could I sum the values of a select when it repeats the client id?
Example
Use this select:
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM clientes";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["nome"]. " - " . $row["valor"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
Result:
Manoel - $ 20.00
Manoel - R $ 40,00
Isac- $ 60.00
Isac- $ 40.00
John- $ 40.00
How do I need to add the values without repeating the names of the clients:
Manoel - $ 60.00
Isac- $ 100.00
John- $ 40.00