i have created sql function called get_fan_count. need retrieve data particular user. how can using db_select. using db_query can fetch value. can't using db_select().
below code working
$query = db_query("select uid, get_fan_count(uid) fan_cnt users name '%test%'");
i need deal db_select
the addexpression() method you're looking for:
$query = db_select('users', 'u') ->fields('u', array('uid')) ->condition('u.name', '%' . db_like($string) . '%', 'like'); $query->addexpression('get_fan_count(uid)', 'fan_cnt'); foreach ($query->execute() $result) { // ... }
Comments
Post a Comment