Custom Web Applications to Grow Your Business

(256) 429-8145

Using regex on cakephp select statement

Here are three examples of using regex on cakephp mysql select statement

Include Numbers $this->set('subdivisions', $this->Hsv->find('all', [ 'fields' => array('Subdivision'), 'conditions' => [ 'City' => $homes[0]['Hsv']['City'], 'Hsv.ListingStatusID' => 'Active', 'Subdivision REGEXP "[0-9]"' ], 'group' => array('Subdivision') ])); Begin with Numbers $this->set('subdivisions', $this->Hsv->find('all', [ 'fields' => array('Subdivision'), 'conditions' => [ 'City' => $homes[0]['Hsv']['City'], 'Hsv.ListingStatusID' => 'Active', 'Subdivision REGEXP "^[0-9]"' ], 'group' => array('Subdivision') ])); Only letters and space NO numbers (alpha not numeric) $this->set('subdivisions', $this->Hsv->find('all', [ 'fields' => array('Subdivision'), 'conditions' => [ 'City' => $homes[0]['Hsv']['City'], 'Hsv.ListingStatusID' => 'Active', 'Subdivision REGEXP "^[a-zA-Z ]+$"' ], 'group' => array('Subdivision') ]));