Page 1 of 1

Need help with Random function with Limit Variable

Posted: Thu Apr 15, 2004 12:51 pm
by ghank
I have a php script that sets a variable:

Code: Select all

$links=15;
And it has an include statement like this:

Code: Select all

include("template.php");
And in the template file I have a RAND function which currently pulls 15 entries from mysql.

Code: Select all

$sql_query = "SELECT * FROM LINKS ORDER BY RAND() LIMIT 15";
Anybody know how to put the $links variable in place of the LIMIT 15? I want to be able to change the $links variable in the original php file to vary the amount of links displayed on the page. I am new to PHP and couldn't find the answer anywhere. Thanks in advance!

Posted: Thu Apr 15, 2004 1:01 pm
by xisle
LIMIT $links should work..

Posted: Thu Apr 15, 2004 2:14 pm
by ghank
Tried that and it produced zero results.

Posted: Thu Apr 15, 2004 2:16 pm
by magicrobotmonkey
echo it before you submit it an see what it says

Posted: Thu Apr 15, 2004 3:13 pm
by ghank
I echoed it and it returned 15 so it captured the variable. It's just a matter of sticking in the string.

Posted: Thu Apr 15, 2004 3:16 pm
by ghank
Hey, it works now. I tried again and inserting $links for 15 did it. I could have sworn I tried that before. Anywho, thanks for the info guys!