I am struggling to find out why my query is returning zero rows. I have extensively tried to figure this out at this question with no decent results.
The jist of it is:
$mydate=date("Y-m-d",strtotime("-3 months"));
$foo_query=$DBH->prepare("SELECT * FROM BarTable WHERE postdate = :postdate AND postdate > '$mydate' ORDER BY postdate DESC");
$foo_query->execute( array('postdate' => $_REQUEST['postdate']) );
EDIT : This query is supposed to say take the date, set it three months in the past, and call it $mydate. Then take all fields from BarTable WHERE the postdate is greater than $mydate, then execute the query.
It has just been pointed out to me that what I have said is that I’m selecting rows where the postdate is equal to 3 months ago and also greater than $mydate.
I don’t understand how I’m saying this. :postdate is not equal to 3 months ago so postdate = :postdate can’t be selecting rows where the postdate is equal to 3 months ago.
To display my rows correctly I was previously typing WHERE postdate > '$mydate'.
How can I type postdate = :postdate AND postdate > '$mydate' so that I am using a parameter and also making sure that data is selected based on being greater than $mydate?
you need to bind the parameter for
postdate. also, to get both critierias satisfied,postdate = :postdate and postdate > $mydate, you need to useORin your query.OR similar to what you mentioned in your question, you missed the
:when assigning the:postdate,