CodeIgniter或Ignited Datatables的长尾where子句

时间:2016-01-09 13:23:07

标签: mysql codeigniter datatables where-clause

我正在尝试编写一个长尾where语句,其中包含另一个选择查询以及如何执行此操作。目前,我正在使用Ignited Datatables Library和我的CodeIgniter 3安装。

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 个答案:

答案 0 :(得分:1)

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

$id

第二个字符串应该以相同的方式修复。同时检查您的TEST(MyTestGroup, TestAdd_1) { p = Add(); // the above function delete[] p; // <--- Use correct delete for arrays } param是否已正确转义。