megetron Posted February 20, 2012 Share Posted February 20, 2012 Hi, why my query doesnt work and the order doesnt work. instead of ordering by a number its order by a string. here is query: $sql = " SELECT * FROM p_transaction AS t, p_joinpgm AS j,p_merchant as m"; $sql .= "where AND t_joinpgmid = '$joinid' AND t.t_joinpgmid = j.joinpgm_id AND j.joinpgm_merchantid=m.merchant_id order by t_id desc"; Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 20, 2012 Share Posted February 20, 2012 Your query is malformed. Right after the WHERE clause you have an "AND". Run your query through PHPMyAdmin to get it right - then create it in the code. Also, it does look like the fields referenced in the WHERE and ORDER BY clauses have an improper field name. I assume "t_joinpgmid" should be "t.joinpgmid" and "t_id" should be "t.id". I would also suggest using JOINS instead of joining the data in the WHERE clause SELECT * FROM p_transaction AS t JOIN p_joinpgm AS j ON t.t_joinpgmid = j.joinpgm_id JOIN p_merchant as m ON j.joinpgm_merchantid = m.merchant_id WHERE t.joinpgmid = '$joinid' ORDER BY t.id desc And, lastly, list out the fields you need in the SELECT clause rather than using '*'. It's inefficient to be querying data that you won't use Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 20, 2012 Share Posted February 20, 2012 If you were to run that, you would have this query (view the bold portion) SELECT * FROM p_transaction AS t, p_joinpgm AS j,p_merchant as mwhere AND t_joinpgmid = '$joinid' AND t.t_joinpgmid = j.joinpgm_id AND j.joinpgm_merchantid=m.merchant_id order by t_id desc add a space after the "m" in the first part or before the "where" in the second part. Also, as Psycho stated, remove the "AND" after the "where" 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.