简体   繁体   中英

MYSQL Query ignoring results in php

editing this question as it has been narrowed down more. If i manually run a SQL query as per below, it shows no results even though i know that nfw_lead_messages_sent.reply = '2' has at least 5 results that should show.

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

If i manually run with SQL query nfw_lead_messages_sent.reply = '1' the results show. See below for one that works with = '1' but doesnt work when i change it to = '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

first thing cast $data to integer

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

then use it as follows

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM