0

I have an android application that uses a sqlite database. My app has a next and previous button to view entries in the database. I need to check whether or not a next or previous entry exists that way i can disable the button if one does not exist.

2 Answers 2

1

Run a query to get the IDs of each record in the table and cache this. Then you know if there are next or previous entries. Click the button, and your app would do a primary key lookup based on the cached data.

Sign up to request clarification or add additional context in comments.

Comments

1

Try something like this:

SELECT *, (SELECT id FROM my_table WHERE id < <my_id> ORDER BY id DESC LIMIT 1) AS previous_id, (SELECT id FROM my_table WHERE id > <my_id> ORDER BY id ASC LIMIT 1) AS next_id FROM my_table WHERE a = <my_id> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.