php - CodeIgniter where and like sql 查询语句

标签 php mysql sql codeigniter

我正在尝试在 codeigniter 上执行此 sql 查询

SELECT* FROM person WHERE type = 'staff' AND description LIKE 'university%'

我不确定是否正确...

$this->db->get_where('person' , array('type'=>'staff'))
         ->like('description','university%')
         ->result_array();

有人知道我的案子吗?提前致谢...

最佳答案

使用 Active Record你可以这样做

$query = $this->db->select('*')
             ->from('person')
             ->where('type','staff')
             ->like('description','university','after')
             ->get();

$result = $query->result_array();

确保将 after 作为 like() 函数中的第三个参数传递,这样 active record 将添加通配符,即 %university 所以它看起来像 LIKE 'university%'

关于php - CodeIgniter where and like sql 查询语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23027385/

相关文章:

php - MYSQL如何排序结果

php - xls 文件 php 下载的格式与文件扩展名指定的格式不同

php - 在php中获取mysql用户定义的变量

javascript - 循环遍历php mysql中的json数据来获取javascript函数

php - 搜索 - 空条件字段

sql - 即使 where 子句删除了这些结果,如何显示联接结果

SQL Server Compact 查询分析器 : How to change part of a string value in a table?

php - Laravel 查询生成器使用 MySQL 中的变量进行复杂选择?

php - SQL排除某些行

sql - 如何在不访问源代码的情况下确定 Oracle 查询?