salman_ahad@yahoo.com Posted November 2, 2009 Share Posted November 2, 2009 I am still getting error.. $Var=$_POST['limit']; $VarCount = mysql_real_escape_string($Var); $query = mysql_query("SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) AND LIMIT $VarCount ORDER BY datetime DESC ") or die(mysql_error()); //error //You have an error in your SQL syntax;...check near LIMIT...etc If I replace $VarCount(user defined) by 2,3,4(any integer).....it is working. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/179905-solved-mysql-limit-error/ Share on other sites More sharing options...
bubbasheeko Posted November 2, 2009 Share Posted November 2, 2009 I'm a fan of using quotes... $query = mysql_query("SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) AND LIMIT " . $VarCount . " ORDER BY datetime DESC ") or die(mysql_error()); And the people who have posted below are absolutely correct. Limit needs to be at the end.... Quote Link to comment https://forums.phpfreaks.com/topic/179905-solved-mysql-limit-error/#findComment-949039 Share on other sites More sharing options...
taquitosensei Posted November 2, 2009 Share Posted November 2, 2009 set your sql to a variable and then echo it to make sure it looks like it should. $VarCount=mysql_real_escape_string($_POST['limit']); $sql="SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) AND LIMIT $VarCount ORDER BY datetime DESC " echo $sql; $query=mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/179905-solved-mysql-limit-error/#findComment-949040 Share on other sites More sharing options...
mikesta707 Posted November 2, 2009 Share Posted November 2, 2009 you have to put the LIMIT at the end of the query. IE $query = mysql_query("SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) ORDER BY datetime DESC LIMIT $VarCount ") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/179905-solved-mysql-limit-error/#findComment-949043 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted November 2, 2009 Author Share Posted November 2, 2009 Only Taqui and Mike worked... if(isset($_POST['Submit'])) { $VarCount=mysql_real_escape_string($_POST['limit']); $query = mysql_query("SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) ORDER BY datetime DESC LIMIT $VarCount") or die(mysql_error()); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/179905-solved-mysql-limit-error/#findComment-949053 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.