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 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码