I just want to know if there is a way to do this process doing just one call to the database.
I basically need to count entries from a database where today’s date is older than the field ‘date_out’ + 7 days. I was thinking in something like:
$today = date("Y-m-d"); //this is the format of date_out in my db!
$count_query = "SELECT count(*) FROM `group` WHERE ADDDATE('date_out', INTERVAL 7 DAY) <= $today ";
$count_result = mysql_query($count_query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($count_result);
$number_ty = $query_data[0];
if ($number_ty >= 1) {
// do something
}
$number_ty is always 0 with this code.
The goal of this question, as stated before, is to know if the count can be done in just one mysql call instead of two. I’m aiming to just simplicity, cleanliness and laziness 🙂
Thanks!
You shouldn’t be quoting
date_out:You should be quoting
$today:Here is a corrected query. Nevertheless, I would advise that you look into Mysqli or PDO. The library you’re using is deprecated.