timmah1 Posted July 10, 2009 Share Posted July 10, 2009 I'm trying to grab the last item from the database, based on the date. I need to show if there is one listed for today's date, if there is not, then I have to go back 180 days, and show the last one. I thought this would do it, but I keep getting "Try Again". Here is the code <?php $query3 = "SELECT * FROM specials WHERE sport = 'ncaab' AND startdate BETWEEN '".date("Y-m-d")."' AND '".date("Y-m-d", strtotime("-180 Day"))."' ORDER BY id DESC LIMIT 1"; $w3 = mysql_query($query3); $numrows = mysql_num_rows($w3); if($numrows < 1){ $title1 = "Try again"; } else { $title1 = "Past Special Present"; } ?> Can anybody see the problem? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/165497-solved-select-statement-correct/ Share on other sites More sharing options...
rhodesa Posted July 10, 2009 Share Posted July 10, 2009 first, change $w3 = mysql_query($query3); to $w3 = mysql_query($query3) or die(mysql_error()); do you get any errors? Link to comment https://forums.phpfreaks.com/topic/165497-solved-select-statement-correct/#findComment-872862 Share on other sites More sharing options...
timmah1 Posted July 10, 2009 Author Share Posted July 10, 2009 I get no errors And just so I make this known, I have at least 1 item in the database with this date 2009-03-11, so this item should show Link to comment https://forums.phpfreaks.com/topic/165497-solved-select-statement-correct/#findComment-872866 Share on other sites More sharing options...
timmah1 Posted July 10, 2009 Author Share Posted July 10, 2009 I got it after echoing out the select statement I had the between dates reversed I changed this $query3 = "SELECT * FROM specials WHERE sport = 'ncaab' AND startdate BETWEEN '".date("Y-m-d")."' AND '".date("Y-m-d", strtotime("-180 Day"))."' ORDER BY id DESC LIMIT 1"; to this $query3 = "SELECT * FROM specials WHERE sport = 'ncaab' AND startdate BETWEEN '".date("Y-m-d", strtotime("-180 Day"))."' AND '".date("Y-m-d")."' ORDER BY id DESC LIMIT 1"; and it works now Link to comment https://forums.phpfreaks.com/topic/165497-solved-select-statement-correct/#findComment-872877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.