timmah1 Posted June 2, 2008 Share Posted June 2, 2008 I'm trying to grab everything from the database that is equal to or greater than today's day. I have this code $today = date("Y-m-d"); $search = "SELECT * FROM photos WHERE weeks >= $today"; $query = mysql_query($search) or die(mysql_error()); $total = mysql_num_rows($query); if($total == 1) { while ($row = mysql_fetch_assoc($query)) { echo "$row[photo]"; } } But it don't show the one record that's in there. The record has weeks as 2008-06-02, so it should show, but nothing shows. Is this the correct way? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/108441-solved-finding-greater-than/ Share on other sites More sharing options...
radar Posted June 2, 2008 Share Posted June 2, 2008 try this.. $today = time(); $search = "SELECT * FROM photos WHERE UNIX_TIMESTAMP(weeks >= $today)"; $query = mysql_query($search) or die(mysql_error()); $total = mysql_num_rows($query); if ($total == 0) { while ($row = mysql_fetch_assoc($query)) { echo $row[photo]; } } -- this hasnt been tested and it might not work but its worth a try Quote Link to comment https://forums.phpfreaks.com/topic/108441-solved-finding-greater-than/#findComment-555940 Share on other sites More sharing options...
metrostars Posted June 2, 2008 Share Posted June 2, 2008 Try <?php $search = "SELECT * FROM photos WHERE weeks >= CAST('$today' AS DATE)"; ?> OR if it's only going to be todays date <?php $search = "SELECT * FROM photos WHERE weeks >= NOW()"; ?> You could also try to use <?php $today = date("Y-m-d"); $search = "SELECT * FROM photos WHERE weeks >= $today"; $query = mysql_query($search) or die(mysql_error()); $total = mysql_num_rows($query); //if($total == 1) { while ($row = mysql_fetch_assoc($query)) { echo "$row[photo]"; } // } ?> to see if there are more than 1 rows being returned. Quote Link to comment https://forums.phpfreaks.com/topic/108441-solved-finding-greater-than/#findComment-555941 Share on other sites More sharing options...
timmah1 Posted June 2, 2008 Author Share Posted June 2, 2008 thank you metrostars, that worked perfect! Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/108441-solved-finding-greater-than/#findComment-555947 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.