dickm Posted June 23, 2011 Share Posted June 23, 2011 I have the following query which when pasted into phpmyadmin sql works and returns results SELECT h.rec_id AS CapLog, h.remoteid AS Reference, h.branch AS Branch, h.dtplnprtd AS PrelimDate, h.estimate AS Estimate, h.cname AS Company, h.mycustomer AS OurCustomer, CONCAT_WS( ' ', RTRIM( h.jobsite1 ) , RTRIM( h.jobsite2 ) , RTRIM( h.jobsite3 ) , RTRIM( h.jobsite4 ) , RTRIM( h.jobsite5 ) , RTRIM( h.jobsite6 ) , RTRIM( h.jobsite7 ) ) AS Jobsite, h.contractor AS Contractor FROM history h INNER JOIN customer c USING ( cusid ) WHERE c.username = 'USERCPO' AND h.dtplnprtd BETWEEN '20110524' and '20110622' ORDER BY mycustomer ==================================================================================================================== Now the same query but using the variables instead of the static data in RED above returns no results in my script file??? $query = "SELECT h.rec_id AS CapLog, h.remoteid AS Reference, h.branch AS Branch, h.dtplnprtd AS PrelimDate, h.estimate AS Estimate, h.cname AS Company, h.mycustomer AS OurCustomer, CONCAT_WS( ' ', RTRIM( h.jobsite1 ) , RTRIM( h.jobsite2 ) , RTRIM( h.jobsite3 ) , RTRIM( h.jobsite4 ) , RTRIM( h.jobsite5 ) , RTRIM( h.jobsite6 ) , RTRIM( h.jobsite7 ) ) AS Jobsite, h.contractor AS Contractor FROM history h INNER JOIN customer c USING ( cusid ) WHERE c.username = '$remcode' and h.dtplnprtd BETWEEN '$dbegin' and '$dend' ORDER BY mycustomer"; Any ideas as to what is wrong would be appreciated. Link to comment Share on other sites More sharing options...
Paul Swanson Posted June 23, 2011 Share Posted June 23, 2011 Nothing jumps out as looking wrong. Right after you run the query, add this: echo '<p>MySQL Error: ' . mysql_error() . '</p>'; Does MySQL report any errors? 1 Link to comment Share on other sites More sharing options...
dickm Posted June 23, 2011 Author Share Posted June 23, 2011 No errors are reported by MYSQL. I just added your error check and no errors. Also I have echoed the variables and they are the same as the static data, so I am really puzzled. Link to comment Share on other sites More sharing options...
Larry Posted June 24, 2011 Share Posted June 24, 2011 Have you confirmed the values of the variables? In other words, if you print out the query being executed by PHP is it the exact same? Link to comment Share on other sites More sharing options...
Antonio Conte Posted July 5, 2011 Share Posted July 5, 2011 The only thing I can thing of is the USING part. I'm not familiar with that way of writing joins, but I notice it's the only thing without h. or c.. Don't know if that is the problem. You could try to rewrite it like INNER JOIN customer c ON ( c.cusid = h.a_field_with_customer_id* ) You obviously need to change it according to your fields to join with. Link to comment Share on other sites More sharing options...
Recommended Posts