Zend DB 连接两列
您好,我有一个小函数,用于搜索用户详细信息(它是 ajax 搜索)。目前我使用的函数是这样的:
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);
}
如您所见,如果我要写一个用户 first_name
OR last_name
OR 用户名
我可以找到他们的详细信息。
我想要做的就是对搜索进行更多的微调,所以如果我写 first_name last_name
它会微调结果。
我发现了几个看起来可行的问题 (参见此处),如果我从一个表获取数据,但我不确定如何使用连接来合并它,而是坚持使用 Zend 语法比使用普通的旧的 SQL 语句?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,答案比我想象的要简单得多,我整个上午都在搞乱,试图找到一个可能过于复杂的解决方案,提出问题后就离开了,我突然意识到要尝试:
这对我有用,我'我不确定它的方法是否正确,但它有效,所以我将其留在这里,以防它对其他人有帮助。
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:
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.