Reputation: 23
Hey there I have a table (named vanzari) with a column named totaldeplata i want to display the sum of all numbers from column nammed totaldeplata from current date, there is a column nammed datainregistrarii where is registered the date by this
format Dec 7, 2017 - 12:51
this is the code, i don't get any errors but it does not display the sum
<?php
$query = "SELECT * FROM vanzari WHERE datainregistrarii >= CURRENT_DATE()";
$query_run = mysql_query($query);
$qty= 0;
while ($num = mysql_fetch_assoc ($query_run)) {
$qty += $num['totaldeplata'];
}
echo $qty;
?>
Any idea why it doesn't display the sum of column from the current day?
Upvotes: 0
Views: 174
Reputation: 23
I really apreciate your answear, none of them are not working. This is what i got.
<?php
(int)$num['totaldeplata'];
$query = "SELECT * FROM vanzari WHERE datainregistrarii >= CURRENT_DATE()";
$query_run = mysql_query($query);
$qty= 0;
while ($num = mysql_fetch_assoc ($query_run)) {
$qty += (int)$num['totaldeplata'];
}
echo $qty;
?>
Upvotes: 0
Reputation: 36
There 2 possibilities :
Using Query you can get total. SELECT SUM(totaldeplata) FROM vanzari WHERE datainregistrarii >= CURRENT_DATE()
You can Type Cast the variable. ie: (int)$num['totaldeplata'];
$query = "SELECT * FROM vanzari WHERE datainregistrarii >= CURRENT_DATE()"; $query_run = mysql_query($query);
$qty= 0;
while ($num = mysql_fetch_assoc ($query_run)) {
$qty += (int)$num['totaldeplata'];
}
echo $qty;
?>
Thanks
Upvotes: 1