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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

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

Post 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??
ReDucTor
Forum Commoner
Posts: 90
Joined: Thu Aug 15, 2002 6:13 am

Post 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.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post 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?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

excellent solution.. thanks... as we say in spanish: "es mas pintoresca" ...
Post Reply