开发者

Zend DB Concatenate two columns

Hello I have a small function which I use for searching for a users details (its an ajax search). At the moment the function I use is this:

public function findAllUsersLike($like)
{
    $select = $this->select(Zend_Db开发者_如何转开发_Table::SELECT_WITH_FROM_PART)->setIntegrityCheck(false);
    $select->where('users_table.username LIKE ?', '%'.strip_tags($like).'%')
           ->orWhere('users_data.first_name LIKE ?', '%'.strip_tags($like).'%')
           ->orWhere('users_data.last_name LIKE ?', '%'.strip_tags($like).'%')
           ->join('users_data', 'users_table.id = user_id', array('first_name', 'last_name'));
    return $this->fetchAll($select);
}

As you can see, if I were to write a users first_name OR last_name OR username I can find their details.

What I want to be able to do is fine tune the search a little more, so if I were to write first_name last_name it would fine tune the results.

I have found a couple of questions which look like they would work (see here), if I were getting the data from one table, but I'm not sure how to incorporate this with using a join but sticking with the Zend syntax rather than using a plain old SQL statement?


OK so the answer was a lot simpler than I had thought, I've been messing all morning trying to find possibly an over complex solution, asked the question and gone away and it dawned on my to try:

->orWhere('CONCAT(users_data.first_name, " ", users_data.last_name) LIKE ?', '%'.strip_tags($like).'%')

This works for me, I'm not sure its the correct method, but it works so I will leave it here in case it helps anyone else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜