duangou6446 2014-04-18 07:50
浏览 24
已采纳

如何在cakephp代码中使用Sql的“like”功能

Hi I have a code in which I am sending a keyword in URL so when we click on link its going to our website so for that I am checking what keyword value is coming in URL in my controller

$keyword= $this->params['url']['keyword'];

$dUsers = $this->Db_user->find(
    'all',
    array(
        'conditions'=>array('Db_user.area_of_expertise'=>$keyword),
        'order'=>array('Db_user.last_name'=>'asc')
    )
);

So my databse has keywod value like : ab ab,bc,ca ab,cd so what is happening by this its giving only ab keyword in result but I need all 3 result which have my keyword in DB so for it I tried to make it like

'Db_user.area_of_expertise'=>'%keyword%'

also tried:

Db_user.area_of_expertise'=>'%'.keyword.'%'

But after it getting no results.

  • 写回答

2条回答 默认 最新

  • doucong6884 2014-04-18 08:09
    关注

    Just use in your conditions array:

    'Db_user.area_of_expertise LIKE' => '%'.keyword.'%'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c51单片机控制步进电机
  • ¥20 Visual studio无法检测到设备
  • ¥15 为什么我通过html绘制的SVG折线图插入到word中坐标轴不显示出来
  • ¥30 vue 页面窗口放大或者缩小元素会变化
  • ¥15 questasim仿真报错
  • ¥15 寻找电脑攻防的导师,有问题请教一下。
  • ¥20 微信同是win11,我的电脑安装不了pageoffice,一直无法打开
  • ¥15 这个界面我通过postman请求不到,但是通过浏览器可以正常访问
  • ¥15 多目标优化算法在与其他算法数据对比结果判断
  • ¥15 CPTN和EAST,主干网络是VGG16,请问在ICDAR2015数据集上训练之后,CPTN和EAST模型的大小为多少