What I need to do
- I have two tables, "chapters" and "pages".
- Each chapter has many pages.
- Chapters are sorted by a position column.
- Pages are sorted by a position column relative to its Chapter. So the first page in each chapter has a position of 1.
- I need to get the 3 pages before and after (if there are 3 pages before/after the current page. ie - on page 2 there is only 1 page before the current)
- I only have the current chapter's 'name' & current page's 'name' attributes.
- I'm using PHP and MySQL
"chapters" Table
- id
- name
- position
"pages" Table
- id
- chapter_id
- name
- position
How do I construct a query that will return an associative array of pages so that I have something as follows (Note: I can use php to do a series of queries if needed):
- pages[0]["id"]
- pages[0]["name"]
- pages[0]["chapter_name"]
Thanks!