By drugget on
Hello everybody!
I've a database query with expression that use regexp.
Everything is working perfectly, but I can't sort the result by expression:
$query = db_select('node', 'n');
$query->addField('n', 'title', 'node_title');
$query->addExpression("title REGEXP '^(.*(compact|watts|different|bulb).*){2}$'", 'r');
$query->orderBy('r', 'DESC'); // this is not working!
$result = $query->execute();
When I comment the string with 'orderBy' - everything is working: expression field has value 0 or 1.
When I enable sorting: expression field always shows 0.
Any ideas?
Thanks, Yuriy.
Comments
Perhaps try n.title and n.r
Using n.title in your addExpression, and n.r in your orderBy may do the trick?
There are times and places to
There are times and places to just use db_query. Maybe this is one of them :)
--
Morris Animal Foundation