MYSQL查询忽略php中的结果

时间:2014-11-18 09:50:13

标签: php mysql

编辑此问题,因为它已经缩小了更多。如果我按照下面手动运行SQL查询,即使我知道nfw_lead_messages_sent.reply =' 2'至少有5个应该显示的结果。

SELECT
CONCAT(title,' ',first_name,' ',last_name) AS lead_name,
nfw_leads.mobile,
nfw_leads.lead_date,
nfw_leads.service_type,
nfw_leads.state,
nfw_lead_messages_sent.reply
FROM
nfw_users
LEFT JOIN nfw_leads ON nfw_leads.allocate_to = nfw_users.id_num
LEFT JOIN nfw_lead_messages_sent ON nfw_lead_messages_sent.sent_to_id = nfw_leads.allocate_to
WHERE
nfw_users.id_num = '3513'
GROUP BY
    nfw_leads.first_name,
    nfw_leads.last_name,
    nfw_leads.mobile,
    nfw_leads.service_type

HAVING nfw_lead_messages_sent.reply = '2'
Order by
    lead_date ASC

如果我使用SQL查询手动运行nfw_lead_messages_sent.reply =' 1'结果显示。请参阅下文,了解适用于=' 1'但是当我将其更改为=' 2'

时不起作用
SELECT
CONCAT(title,' ',first_name,' ',last_name) AS lead_name,
nfw_leads.mobile,
nfw_leads.lead_date,
nfw_leads.service_type,
nfw_leads.state,
nfw_lead_messages_sent.reply
FROM
nfw_users
LEFT JOIN nfw_leads ON nfw_leads.allocate_to = nfw_users.id_num
LEFT JOIN nfw_lead_messages_sent ON nfw_lead_messages_sent.sent_to_id = nfw_leads.allocate_to
WHERE
nfw_users.id_num = '3513'
GROUP BY
    nfw_leads.first_name,
    nfw_leads.last_name,
    nfw_leads.mobile,
    nfw_leads.service_type

HAVING nfw_lead_messages_sent.reply = '1'
Order by
    lead_date ASC

1 个答案:

答案 0 :(得分:0)

首先将$ data转换为整数

   $data = intval($_GET["data"])); 

然后按如下方式使用

   if($data === 1) {
   } elseif($data === 2) {
   } elseif(empty($data)) {
   }