Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Query selecting too many rows

Tags:

php

mysql

I am trying to only select the difference between $from and $to and have those rows outputted in descending order. The problem so far is that I am inputting '5' in as the $from value and '10' into the $to value, but it seems to be outputting 10 rather than 5.

Please could you tell me where I am going wrong?

$query = mysql_query("SELECT * FROM `Posts` WHERE `isPublic` = 'yes' ORDER BY `date` DESC LIMIT $from,$to") or die(mysql_error());  
like image 473
max_ Avatar asked Dec 03 '22 08:12

max_


2 Answers

It's not FROM and TO, it's FROM and HOWMANY.

like image 58
Vinicius Kamakura Avatar answered Dec 23 '22 09:12

Vinicius Kamakura


Check this out: SELECT MySQL documentation.

What you are doing by LIMIT 5, 10 is a synonym to LIMIT 10 OFFSET 5 (get 10 results skipping 5 results from the beginning of the set returned by database).

like image 41
Tadeck Avatar answered Dec 23 '22 10:12

Tadeck