jakebur01 Posted February 26, 2009 Share Posted February 26, 2009 How can I correctly use this query selecting all the rows in the $sort column where the value is 700 or above? $result = mysql_query("SELECT * FROM {$tablename} WHERE $sort > '699' LIMIT 1"); Quote Link to comment https://forums.phpfreaks.com/topic/147024-solved-the-correct-way-to-run-a-select-query/ Share on other sites More sharing options...
micah1701 Posted February 26, 2009 Share Posted February 26, 2009 just get rid of "LIMIT 1" and you should be all set. Quote Link to comment https://forums.phpfreaks.com/topic/147024-solved-the-correct-way-to-run-a-select-query/#findComment-771853 Share on other sites More sharing options...
Maq Posted February 26, 2009 Share Posted February 26, 2009 I would recommend something like this so you can easily debug: $sql = "SELECT * FROM `$tablename` WHERE $sort > 699 LIMIT 1"; $result = mysql_query($sql) or die(mysql_error()); -You don't need anything around $tablename because your whole string is in double quotes and WILL interpolate properly -If I recall correctly, you can use reserved words for table names if you have them encapsulated with backticks, but you don't need them. -Put the statement in a string first so you can echo it out if there are any problems. -Use the or die() clause to output specific MySQL errors. -Like micah mentioned, do you really want the LIMIT 1 in there, it will return only 1 record...? Quote Link to comment https://forums.phpfreaks.com/topic/147024-solved-the-correct-way-to-run-a-select-query/#findComment-771860 Share on other sites More sharing options...
jakebur01 Posted February 26, 2009 Author Share Posted February 26, 2009 That fixed it. I am having trouble in the script as a whole bogging down the server so I had it limited to one row. Thank you all for your help. Quote Link to comment https://forums.phpfreaks.com/topic/147024-solved-the-correct-way-to-run-a-select-query/#findComment-771874 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.