I have a MySQL database and in one column, I have numbers (price) and I need to count all numbers in this column with PHP... How can I do that?
If you want to count the number of columns use:
Select count(column_name) FROM table name.
If you want the sum of column values then use:
Select SUM(column_name) FROM table name.
UPDATE with PHP Code
If you want to count you can do it like this:
$query = "SELECT COUNT(*) FROM table_name"
// Print out result
while($row = mysql_fetch_array($result)){
echo "Total count". $row['COUNT(*)'];
}
If you want to get the sum of one column, you can do like this:
$query = "SELECT SUM(column_name) FROM table_name"
// Print out result
while($row = mysql_fetch_array($result)){
echo "Total sum". $row['SUM(column_name)'];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With