Jump to content

[SOLVED] using variable as limit


severndigital

Recommended Posts

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
Share on other sites


$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.