Mysql REGEXP on Cakephp
Posted on August 27th, 2008 in Programming |
Here is a small tutorial on how to use mysql’s regular expression RegExp on cakephp 1.1 or 1.2.
The regular expression will find the records that start with the value of $letter followed by any number of Alphanumeric, space or quote.
Using Query
$condition = "1=1 AND Artist.name REGEXP
'^[$letter][A-Za-z0-9 \']*’”;
$this->paginate(”Artist”,$condition);
Using Array
$condition = array('Artist.name'=>"REGEXP
^[$letter][A-Za-z0-9 ']*”);
$this->paginate(”Artist”,$condition);
Using Find Method
1.2 (Tested)
$data = $this->Artist->find("all",array("condition"=>
array('Artist.name REGEXP'=>"^[$letter][A-Za-z0-9 ']*”)));
1.1: Tested before don’t know if it still works
$data = $this->Artist->findAll(array(’Artist.name’=>
“REGEXP ^[$letter][A-Za-z0-9 ']*”));
Hope this helps ![]()












