php - 在 Ignited Datatables 中使用 where 和 like

标签 php mysql codeigniter datatable

如何在构建查询以获得结果时使用 codeigniter 的 Ignited Datatables 实现Where和Like。

我尝试过的代码如下:

$meter_id="12345";
$meter_id="'%".$meter_id."%'";
$this
    ->datatables
    ->select('Log_Name,Log_Creation_Date_Time,User_Name')
    ->from('Log_Data')
    ->where('Log_Name LIKE', $meter_id); //(Trying to Build LIke statement Here)
echo $this->datatables->generate();

$meter_id="12345";   
$this
    ->datatables
    ->select('Log_Name,Log_Creation_Date_Time,User_Name')
    ->from('Log_Data')
    ->like('Log_Name', $meter_id);
echo $this->datatables->generate();

但是上面的两个代码都不起作用。 我还检查了 Codeigniter 的 Ignited Datatables 的文档,但没有找到任何使用 LIKE 关键字构建查询的示例。

我必须构建的查询:

SELECT 
    Log_Name,
    Log_Creation_Date_Time, 
    User_Name 
FROM Log_Data
WHERE Log_Name LIKE '%12345%'

我该如何实现这个?

最佳答案

尝试一下

$meter_id="12345";   
$this->db->select('Log_Name,Log_Creation_Date_Time,User_Name')
         ->from('Log_Data')
         ->like('Log_Name', $meter_id);
$result = $this->db->get();
print_r($result);

关于php - 在 Ignited Datatables 中使用 where 和 like,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18395090/

相关文章:

php - 更新php和mysql数据库中的图像

php - Smarty foreach mysql 问题

PHP加密SQL

php - 将数据库查询的结果插入 Controller 中的变量中 - CODEIGNITER

php - Codeigniter : who should call show_error()中的错误处理

php - 为什么html页面读不到php页面

java - 如何连接同一个表中的两列

mysql - Group By MySQL 查询返回带有参数的特定结果

php - 获取当前季度的开始日期和结束日期 php

php - 如何在 mac osx mamp 上为 php 安装 apc?