geroido Posted September 12, 2008 Share Posted September 12, 2008 Hi I have two tables that I'm trying to join and get results from - orderdetails and menuitemdetails. What I'm trying to do is pull all the the orders from orderdetails pertaining to a particular client. The client id is held in menuitemdetails and I use $_SESSION['clsrevid']." to compare it. Now the query is getting every record regardless of the id held in $_SESSION['clsrevid'].". Any idea why it's not just getting the records of the specific client. the clientID is of the form CLS_owen4785f5b9ce484 or CLS_carey4780bc7a6e1bc. I've echoed the query and it seems ok. The echo result is: SELECT orderdetails.Ordernum, SUM(orderdetails.itemcost * orderdetails.ItemQuantity) as mytotal, orderdetails.CustFName, orderdetails.CustSName, orderdetails.StreetAddr, orderdetails.Town, orderdetails.County, orderdetails.TelNum, orderdetails.orddate, ClientID from orderdetails left join menuitemdetails on orderdetails.MenuItemID=menuitemdetails.MenuItemID and ClientID = ' CLS_owen4785f5b9ce484' group by orderdetails.Ordernum actual query: $query = "SELECT orderdetails.Ordernum, SUM(orderdetails.itemcost * orderdetails.ItemQuantity) as mytotal, orderdetails.CustFName, orderdetails.CustSName, orderdetails.StreetAddr, orderdetails.Town, orderdetails.County, orderdetails.TelNum, orderdetails.orddate, ClientID from orderdetails left join menuitemdetails on orderdetails.MenuItemID=menuitemdetails.MenuItemID and ClientID = '".$_SESSION['clsrevid']."' group by orderdetails.Ordernum "; Quote Link to comment Share on other sites More sharing options...
fenway Posted September 12, 2008 Share Posted September 12, 2008 You're using GROUP BY -- you can't then examine anything other than aggregate functions. So the other columns have meaningless values in them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.