husin.anti husin.anti - 4 months ago 6
SQL Question

Remove text result from SQL query in PHP

i have this code :

$result = mysqli_query($conn, "SELECT SUM(angsuran) FROM `laporan` WHERE id_mustahik=".$detail_campaigner->id_mustahik."");
$row = mysqli_fetch_assoc($result);
print_r($row);


when i run this code, the result is :

Array ( [SUM(angsuran)] => 30000 )


But i want it to display just "30000" number, without "Array ( [SUM(angsuran)] => ) ".

How can i do that ?

Answer

add alias in your query like

$result = mysqli_query($conn, "SELECT SUM(angsuran) as sumtotal FROM `laporan` WHERE id_mustahik=".$detail_campaigner->id_mustahik."");
$row = mysqli_fetch_assoc($result);
echo $row['sumtotal']; //outputs 30000