Jump to content

[SOLVED] Select statement correct?


timmah1

Recommended Posts

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

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.