php - $this->query() 中条件为空的 Codeigniter

标签 php mysql codeigniter

我现在面临着非常奇怪的情况。我在 CodeIgniter 中使用如下 WHERE 条件编写了一个查询:

$queryps = $this->db->query("SELECT count(workorderno) as total from crm_workorder where workorderno =".$sitecode.""); 

但是我收到了这个错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

SELECT count(workorderno) as total from crm_workorder where workorderno =

现在奇怪的是变量 $sitecode 不是空的。当我回显查询时,它显示如下:

SELECT count(workorderno) as total from crm_workorder where workorderno =2

但是在 SQL 查询中,我遇到了上述错误。 WHERE 条件下没有任何内容。

我尝试了各种可能的方法来找出背后的原因,但我无法弄清楚这一点。谢谢。

最佳答案

这就是您所需要的,它必须在您的模型中。

<?php

    $this->db->select("SELECT count(workorderno) as total");
    $this->db->from("crm_workorder");
    $this->db->where("workorderno",$sitecode);

    $queryps = $this->db->get();

?>

关于php - $this->query() 中条件为空的 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53884387/

相关文章:

php - 抓取没有 HTML 的纯文本文件?

javascript - 如何在不打开外部链接的情况下访问它,只需加载它

PHP Codeigniter foreach 崩溃

mysql - 如何使用 Rails 优化此查询

javascript - TypeError : oTable. fnReloadAjax 不是函数 - DataTables

javascript - 在文本区域中找到超链接的现有编号 设置下一个可用的编号保存/单击模式

php - 在php中找到正确的FFmpeg路径

javascript - Chrome 没有完全安慰 JS 对象

php - 使用 PHP 连接到 mySQL,连接昨天有效,但今天不行

mysql - 将查询结果中的 id 外键替换为用户名