Page 2 of 2

Posted: Thu Mar 11, 2004 8:58 am
by Weirdan
That's why I proposed dinamic renumbering using SQL variables. Forgot to mention that if you go this way you need to include ORDER BY clause into your queries. Otherwise order of the rows would be undefined.

PS: welcome back, Volka ;)

Posted: Thu Mar 11, 2004 6:41 pm
by josh
volka wrote:I strongly advise against tempering with auto_increment fields - esp. if it's only to have continuous values. There are good reasons why they behave this way. Speed: your renumbering takes a considerable amount of time, ever more with an increasing amount of records. Uniqueness: an auto_increment field is supposed to identify a record, but it doesn't if you assign new ids. Yesterday id=2 identified record a, today it's record b - hmmmm.

There's another property assigned to the records which is always continuous. The position within the result set. You may use it within the database, e.g.
SELECT a,b, from tablename WHERE <condition> LIMIT 4,2
(get records 5 to 6 that fulfill the condition) and/or within your script/program

ok but how would i say the following


if page =1 get 1-5
if page =2 get 6-10 etc.... right now i have $page is the page im on and get $page * 5

the only problem is if the 3rd item in the database has an id of 27 for example because ive deleted alot of items i say get where id >6 limit 5 for example... it returns nothing right.. or would it keep returning items until 5 are returned?