goeiu3eu
goeiu3eu

Reputation: 39

Select date for today

Table: id, confess, user_ip, time, url, loves, hate

Time is like 1413040760

$q = mysql_query("SELECT * FROM confessions where time >= unix_timestamp(curdate() + interval 1 day)") or die(mysql_error());

I need the best confess of day order by loves limit 1. This show my only blank, no results.

Upvotes: 2

Views: 75

Answers (1)

Mureinik
Mureinik

Reputation: 312257

You're querying records that happened later than one day from now - i.e., in the future. Presumably, you don't have any records like that. You can change the + interval 1 day to - interval 1 day in order to get records that occurred up to 1 day ago.

$q = mysql_query("SELECT * FROM confessions where time >= unix_timestamp(curdate() - interval 1 day)") or die(mysql_error());

EDIT: To answer the question in the comment, yes, it's possible to sort by loves - hates - just slap on an order by clause:

$q = mysql_query("SELECT * " .
                 "FROM confessions " .
                 "WHERE time >= unix_timestamp(curdate() - interval 1 day) " .
                 "ORDER BY (loves - hates) DESC" ) or die(mysql_error());

Upvotes: 2

Related Questions