Question

i am using cakephp and creating this condition:

$conditions = array("Userword.levelid"=>0, "Userword.userid"=>$this->Auth->user('UserId'),"date(Userword.date)"=>"DATE_SUB(CURDATE(),INTERVAL 0 DAY)");  
$Userword = $this->paginate(null, $conditions);

cake using this select :

`Userword`.`userwordid`, `Userword`.`userid`, `Userword`.`wordid`, `Userword`.`date`, `Userword`.`levelid`, `Word`.`wordid`, `Word`.`word`, `Word`.`meaning`, `User`.`UserId`, `User`.`Email`, `User`.`password`, `User`.`username`, `User`.`cell`, `User`.`web` FROM `userwords` AS `Userword` LEFT JOIN `words` AS `Word` ON (`Userword`.`wordid` = `Word`.`wordid`) LEFT JOIN `users` AS `User` ON (`Userword`.`userid` = `User`.`UserId`) WHERE date(`Userword`.`date`) = 'DATE_SUB(CURDATE(),INTERVAL 2 DAY)'  

but by this select mysql can't return record because cakephp in this select use this character (') in last passage. when i remove this character and test this code in phpmyadmin this code return rows. two images in below show this :

cakephp mysql code

image of phpmyadmin without <code>'</code> character

Was it helpful?

Solution

Just don't separate it out as key => value pair:

$conditions = array(
   ...
   'DATE(Userword.date) = DATE_SUB(CURDATE(), INTERVAL 0 DAY)'
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top