Page 1 of 1

mySQL error "near ' 1' at line 1"

Posted: Sun Nov 28, 2010 1:52 pm
by sathoro
I have the following code

Code: Select all

$result = mysql_query("SELECT * FROM wallpapers WHERE resolution = '$resolution' ORDER BY id DESC LIMIT $random, 1")
and it is getting the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 1' at line 1
I've tried putting $random in quotes, spacing it differently, etc. but I have no idea what is causing the error. Any ideas?

Thanks!

Re: mySQL error "near ' 1' at line 1"

Posted: Sun Nov 28, 2010 1:59 pm
by sathoro
oh, and $random is from:

Code: Select all

$numbers = range(1, $j);
shuffle($numbers);
$random = $numbers[$c_rand];

Re: mySQL error "near ' 1' at line 1"

Posted: Sun Nov 28, 2010 3:05 pm
by sathoro
fixed it! turns out it was from going out of the array's bounds. this fixed it:

Code: Select all

if ((count($numbers) - 1) >= $c_rand) {
	$random = $numbers[$c_rand]; // gets random number
}