It's been a while since I wrote a "complicated" query and I can't figure out why this isn't work:
When I try this, I get an unknown column "querydate". Can you not use a variable created within the query in the WHERE part? Am I doing something seriously wrong?
Code:
$querydate = "2007-07";
$query = "SELECT *,
DATE_FORMAT(`date`,'%M %e, %Y') AS disp_date,
DATE_FORMAT(`date`, '%m-%d') AS sDate,
DATE_FORMAT(`date`, '%Y-%m') AS querydate
FROM `testimonials`
WHERE `deleted` <> 1 AND
querydate = '".$querydate."'
ORDER BY `winner` DESC,
`sdate` DESC";
When I try this, I get an unknown column "querydate". Can you not use a variable created within the query in the WHERE part? Am I doing something seriously wrong?