Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

  • 2 weeks later...

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

 Share

×
×
  • Create New...