Page 1 of 1

Navigating through A text field (page 1 page 2...)

Posted: Sun May 11, 2003 11:21 am
by AVATAr
How you people do the navigation in a text field.

I have a table that have records with a large text field (stored in a DB). I want to make some kind of pagination (page 1, next ->) with that field. --(in other words, i want to navigato through the textfield in ONE record)

My question is... how do you do that ??? (in the insertion). i found 2 approaches:

1. i insert many records for the same article (one record for each page) in the DB, and then i implement som kind of next_previous script. -- i dont think its the best solution

2. i insert a tag in the text field like: [Page x]. When i want to show the page i use some var in the url (or post) with the page id, and then i parse it.

any comments? how do you do that??

Posted: Sun May 11, 2003 12:03 pm
by ReDucTor
I recommend:

Add a field to your table which is the page, then divid the text up, into different rows, and for the first page it has a page of 0 or 1, then they increase from this, only show as the articles/documents being the ones with the page of 0 or 1 which ever is the first page.

Posted: Sun May 11, 2003 1:20 pm
by AVATAr
OK, but thinking about the DB design... if i have this

ID - Autoincrement Key
Text

i can add a Page field.. like this

ID - Key
Page - Key
Text

The problem here is the key field (in this case ID)

The best design would be using the key as: ID, Page.

any comments?

Posted: Sun May 11, 2003 5:46 pm
by McGruff
You could put a string like [--PAGEBREAK--] into the text where you want pages to break.

Next get an array of pages with:

$text = explode("[--PAGEBREAK--]", $text);

Array keys start at 0 so:

$text[0] is page 1, $text[1] is page two etc.

If you pass 0, 1, 2 etc to the script in the query string you can use that to select a page. It should be simple to create a "page 1 of 4 ... 1 | 2 | 3 | 4" type nav link to display on each page.

Also:

$total_pages = count($text); // AFTER you've exploded $text

Posted: Sun May 11, 2003 6:13 pm
by AVATAr
excellent solution.. thanks... as we say in spanish: "es mas pintoresca" ...