severndigital Posted June 28, 2008 Share Posted June 28, 2008 can this be done? if so, i can't seem to figure it out. using this query mysql doesn't like it. $limvar = 3; $sql = "SELECT * FROM table WHERE used='0' ORDER BY RAND() LIMIT '$limvar'"; $pull = mysql_query($sql)or die(mysql_error()); when i run this query i get an error saying my syntax is wrong near "3" on line 1 if i run the exact same query but replace '$limvar' with the number 3 .. everything works perfect. any ideas?? Thanks, C Link to comment https://forums.phpfreaks.com/topic/112320-solved-using-variable-as-limit/ Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 $limvar = 3; $sql = "SELECT * FROM table WHERE used='0' ORDER BY RAND() LIMIT $limvar"; $pull = mysql_query($sql)or die(mysql_error()); I would try $limvar with out the speech marks around it as it's an integer and doesn't need these. Link to comment https://forums.phpfreaks.com/topic/112320-solved-using-variable-as-limit/#findComment-576665 Share on other sites More sharing options...
severndigital Posted June 28, 2008 Author Share Posted June 28, 2008 That worked perfectly .. thanks. Link to comment https://forums.phpfreaks.com/topic/112320-solved-using-variable-as-limit/#findComment-576845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.