Re: How to retrieve the position of a row inside a table with garbage data in all cloumns?

From: Date: Tue, 23 Sep 2008 04:20:00 +0000
Subject: Re: How to retrieve the position of a row inside a table with garbage data in all cloumns?
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-45440@lists.php.net to get a copy of this message
En/na Chris ha escrit: > Trullo wrote: >> hello_world(); >> >> in fact.. how to goTo next/previous row of a table without using >> incremental ids AND without reading the whole table? >> i will explain: >> I wanna do something like a paging toolbar blinded to a list of rows >> (for example, a literally view of a db table). >> The first difference from a normal paging system, is that i wanna show >> only one row per page, and luckily i know the id of that first viewed >> row; so, no problem until here. Im able to show the first row xD. >> The second difference is that i don't know the position of the first >> viewed row inside the whole original table, only the id of the row >> (maybe someone is laughing while reading 'only'). >> >> I would like to know the position of that row to allow a easy goTo >> next/prev method using LIMIT/OFFSET sql clauses. > > Assuming the row id you have is a primary key, you could do: > > select * from table where primary_key > $current_rowid order by > primary_key asc limit 1; > > > For previous you could do: > > select * from table where primary_key < $current_rowid order by > primary_key desc limit 1; > Lot of thanks! its true that i dont care about the position of row. Your solution will do the work sure :o] As a curiosity... then.. the only way to know the position of a row, is read the whole table?

« previous php.db (#45440) next »