Re: How to retrieve the position of a row inside a table with garbage data in all cloumns?
| From: | Chris | Date: | Tue, 23 Sep 2008 03:51:02 +0000 |
| Subject: | Re: How to retrieve the position of a row inside a table with garbage data in all cloumns? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-45439@lists.php.net to get a copy of this message | ||
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; -- Postgresql & php tutorials http://www.designmagick.com/