CodeIgniter 或 Ignite Datatables 中的长尾 where 子句

Posted

技术标签:

【中文标题】CodeIgniter 或 Ignite Datatables 中的长尾 where 子句【英文标题】:Long tail where clause at CodeIgniter or Ignited Datatables 【发布时间】:2016-04-14 03:15:31 【问题描述】:

我正在尝试编写一个长尾 where 语句,其中包含另一个选择查询以及我如何做到这一点。目前,我在安装 CodeIgniter 3 时使用 Ignited Datatables 库。

SELECT ContactId,
       ReceiverId,
       SenderId,
       IF(ReceiverId = 1,
            (SELECT first_name
             FROM users
             WHERE users.id = contacts_connectivity.SenderId),
            (SELECT first_name
             FROM users
             WHERE users.id = contacts_connectivity.ReceiverId)) AS FirstName,
       IF(ReceiverId = 1,
            (SELECT email
             FROM users
             WHERE users.id = contacts_connectivity.SenderId),
            (SELECT email
             FROM users
             WHERE users.id = contacts_connectivity.ReceiverId)) AS SenderEmail,
       IF(ReceiverId = 1,
            (SELECT phone
             FROM users
             WHERE users.id = contacts_connectivity.SenderId),
            (SELECT phone
             FROM users
             WHERE users.id = contacts_connectivity.ReceiverId)) AS SenderPhone,
       IF(ReceiverId = 1,
            (SELECT company
             FROM users
             WHERE users.id = contacts_connectivity.SenderId),
            (SELECT company
             FROM users
             WHERE users.id = contacts_connectivity.ReceiverId)) AS SenderCompany,
       ModulesId,

  (SELECT ModuleName
   FROM modules
   WHERE ModuleId = contacts_connectivity.ModulesId) AS ModuledName,
       FROM_UNIXTIME(AddedDate, "%m/%d/%Y") AddedDate
FROM contacts_connectivity
WHERE (ReceiverId = 1
       OR SenderId = 1)
  AND (ReceiverId
       OR SenderId NOT IN
         (SELECT (ReceiverId
                  OR SenderId)
          FROM contacts_connectivity
          WHERE (ReceiverId
                 OR SenderId) = 1))

我注意到我的查询根本没有返回任何数组。我已经尝试过写这样的 where 语句-

$this->datatables->where("(ReceiverId = ' . $id . ' OR SenderId = ' . $id . ')");
$this->datatables->where(" AND (ReceiverId OR SenderId NOT IN (SELECT (ReceiverId OR SenderId) FROM contacts_connectivity WHERE (ReceiverId OR SenderId) = ' . $id . '");

我做错了什么?

【问题讨论】:

【参考方案1】:

您无效的使用参数。试试这样的:

$this->datatables->where("(ReceiverId=$id OR SenderId=$id )");

第二个字符串也应该以同样的方式固定。还要检查您的 $id 参数是否正确转义。

【讨论】:

下面的脚本$this->datatables->where(" AND (ReceiverId OR SenderId NOT IN (SELECT (ReceiverId OR SenderId) FROM contacts_connectivity WHERE (ReceiverId OR SenderId) = $id");

以上是关于CodeIgniter 或 Ignite Datatables 中的长尾 where 子句的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot,JPA和Ignite

错误:无法找到或加载主类 org.apache.ignite.startup.cmdline

查询 CodeIgniter NOW() Sysdate() 或 .?

使用 Couchbase 作为持久性的 Apache Ignite

Apache Ignite 改装 -- 服务异步化支持

ignite客户端安装及使用-DBeaver