Link to home
Start Free TrialLog in
Avatar of austinfx
austinfx

asked on

SQL not working in my SQL statement.

Ok I have a statement  that works in my MySQL Work Bench but when I wrap the query for php the Query no longer works:

Original:
select
                   li.leadID AS id,
                   IFNULL(MAX(ls.created), li.dateMade) AS created,
                   li.dateStatus AS updated,
                   li.status,
                   IF(li.status = 'New', 1,
                     IF(li.status = 'First Message', 2,
                     IF(li.status = 'Second Message', 3,
                     IF(li.status = 'Third Message', 4,
                     IF(li.status = 'Boneyard', 5, 0
                   ))))) AS weight,
                   li.app_stage AS stage,
                   li.sex,
                   li.state,
                   li.zip,
                   li.birthdate AS dob
                   FROM
                   leads_leadInfo li
               LEFT JOIN leads_checkout lc ON li.leadId = lc.leadId AND lc.deleted IS NULL AND lc.created <= '2015-06-15 12:12:00'
                               LEFT JOIN leads_sources ls ON ls.leadId = li.leadId
               WHERE
                   li.call_center_id=0
                   AND lc.id IS NULL
                   AND ls.created > '2015-06-10 8:00:00'
                   AND (li.email IS NULL OR li.email NOT LIKE '%@medigap360.com')

                        AND state IN ('AZ')
                               GROUP BY id
               HAVING weight > 0 AND created > '2015-06-10 8:00:00'
               ORDER BY
                   weight ASC, created DESC
               LIMIT 1000

Open in new window


If I wrap this in a php variable and echo it out and try to exact the  statement it fails. can you see what I am missing?

$sql = "select
                   li.leadID AS id,
                   IFNULL(MAX(ls.created), li.dateMade) AS created,
                   li.dateStatus AS updated,
                   li.status,
                   IF(li.status = 'New', 1,
                     IF(li.status = 'First Message', 2,
                     IF(li.status = 'Second Message', 3,
                     IF(li.status = 'Third Message', 4,
                     IF(li.status = 'Boneyard', 5, 0
                   ))))) AS weight,
                   li.app_stage AS stage,
                   li.sex,
                   li.state,
                   li.zip,
                   li.birthdate AS dob
                   FROM
                   leads_leadInfo li
               LEFT JOIN leads_checkout lc ON li.leadId = lc.leadId AND lc.deleted IS NULL AND lc.created <= '2015-06-15 12:12:00'
                               LEFT JOIN leads_sources ls ON ls.leadId = li.leadId
               WHERE
                   li.call_center_id=0
                   AND lc.id IS NULL
                   AND ls.created > '2015-06-10 8:00:00'
                   AND (li.email IS NULL OR li.email NOT LIKE '%@medigap360.com')

                        AND state IN ('AZ')
                               GROUP BY id
               HAVING weight > 0 AND created > '2015-06-10 8:00:00'
               ORDER BY
                   weight ASC, created DESC
               LIMIT 1000";
echo $sql;

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

when I wrap the query for php the Query no longer works:

How does it not work?
Is there an error - if so what
Is it that the returned results are non existent / not expected?
What library are you using to connect to the database?

If you can post some code to give the query context it might shed some light. The queries posted are identical so it is most likely something in your code / connection that
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial