Sabmin Posted August 4, 2010 Share Posted August 4, 2010 I'm having a weird issue in which i'm trying to pull rows from a table based on the contents of specific fields. My query strings are: $ms = ("SELECT * FROM games WHERE game = 'test' AND playername = '$test' OR opponentname = '$test' ORDER BY playdate DESC LIMIT 25") or die ('Error: '.mysql_error ()); Which works fine until later I try to use: $ms2 = ("SELECT * FROM games WHERE game = 'test2' AND playername = '$test' OR opponentname = '$test' ORDER BY playdate DESC LIMIT 25") or die ('Error: '.mysql_error ()); What is weird is on $ms2 I found if I change it to: $ms2 = ("SELECT * FROM games WHERE playername = '$test' OR opponentname = '$test' AND game = 'test2' ORDER BY playdate DESC LIMIT 25") or die ('Error: '.mysql_error ()); It works... on one page, on the rest neither line works it just pulls every row in the table that fit one of the two name fields. Has anyone experienced anything like this or know why or a fix for this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/209838-help-with-inconsistant-mysql-query-results/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2010 Share Posted August 4, 2010 You must use () in your AND/OR logic to force the order that they are evaluated - "SELECT * FROM games WHERE game = 'test' AND (playername = '$test' OR opponentname = '$test') ORDER BY playdate DESC LIMIT 25" Also, putting or die(...) on the end of a string assgiment does not make any sense, so I did not bother to include that in the query string. Quote Link to comment https://forums.phpfreaks.com/topic/209838-help-with-inconsistant-mysql-query-results/#findComment-1095337 Share on other sites More sharing options...
Sabmin Posted August 4, 2010 Author Share Posted August 4, 2010 great! thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/209838-help-with-inconsistant-mysql-query-results/#findComment-1095340 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.