Reputation: 818
$today = time() - (3600*24);
$Yday = time() - (3600*48);
$getMsgsToday = mysql_query("SELECT * FROM users_msgs WHERE uID = '$USER' AND date > $today");
$countToday = mysql_num_rows($getMsgsToday);
$getMsgsYday = mysql_query("SELECT * FROM users_msgs WHERE uID = '$USER' AND date > $Yday");
$countYday = mysql_num_rows($getMsgsYday);
This is my code for displaying messages latest 24 hours and 48 hours(yesterday).
I got two while for the queries(yesterday and today).
Now if you have something within 24 hours, it will also display in the yesterday while().
I only wish to show yesterday´s messages, with this I mean the 24 hours before today´s 24 hours.
How can I do this, so I dont get these duplicates?
Upvotes: 0
Views: 185
Reputation: 324
$getMsgsYday = mysql_query("SELECT * FROM users_msgs WHERE uID = '$USER' AND date BETWEEN $Yday and $today");
Upvotes: 0
Reputation: 655129
Use BETWEEN … AND …
to select only those between 48 hours and 24 hours ago:
"SELECT * FROM users_msgs WHERE uID = '$USER' AND date BETWEEN $Yday AND $today"
Upvotes: 1