SELECT ... LIMIT 0,1 syntax error

1.4k views Asked by At
    for($nr = 0; $nr < 2; $nr++){

        print $nr; print(gettype($nr));   // prints 0integer 

        $result = mysqli_query($con,"SELECT * FROM phcdl_files 
        ORDER BY file_id DESC LIMIT '$nr',1") 
        or die(mysqli_error($con));
    }

Trying to run the query above but I'm having troubles because of syntax. Running it on PhpMyAdmin with Limit 0,1 works good however

Any idea what's the problem?

3

There are 3 answers

0
Sougata Bose On BEST ANSWER

Try with -

"SELECT * FROM phcdl_files ORDER BY file_id DESC LIMIT $nr,1"
0
jay.jivani On

remove single quotation of $nr veriable from query

QUERY = "select * from tb_name order by id desc limit $nr , 1"
0
RemyG On

I think the issue is that you're adding quote around the 0.

Your SQL query should look like:

"SELECT * FROM phcdl_files ORDER BY file_id DESC LIMIT $nr, 1"