Need help with Random function with Limit Variable

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ghank
Forum Commoner
Posts: 35
Joined: Tue Apr 06, 2004 3:21 pm

Need help with Random function with Limit Variable

Post 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!
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

LIMIT $links should work..
ghank
Forum Commoner
Posts: 35
Joined: Tue Apr 06, 2004 3:21 pm

Post by ghank »

Tried that and it produced zero results.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

echo it before you submit it an see what it says
ghank
Forum Commoner
Posts: 35
Joined: Tue Apr 06, 2004 3:21 pm

Post by ghank »

I echoed it and it returned 15 so it captured the variable. It's just a matter of sticking in the string.
ghank
Forum Commoner
Posts: 35
Joined: Tue Apr 06, 2004 3:21 pm

Post 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!
Post Reply