Jump to content


Help with custom bbcode


3 replies to this topic

#1 Goon2Goblin

    Young Padawan

  • Members
  • Pip
  • 6 posts

Posted 11 August 2008 - 04:21 PM

Hi there,
I am looking for a way for a user to split up their input (say.. a tutorial) into pages.

If you could just throw some ideas on the table (or you know how already :angrylooking: ) just reply and let me know.

I appreciate any help greatly.
I will get to the bottom of this.

Thanks :rolleyes:

#2 Blaatzorrr

    Young Padawan

  • Members
  • Pip
  • 24 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Html,CSS,Javascript,PHP&Mysql and more =)

Posted 11 August 2008 - 04:33 PM

If you mean as the publishing tutorials here at pixel2life the best way to do this is this :

For the pages you can use as ubb something like [page] and the text after a [page] will be a page? ( not do hard? )
And when you show the tutorial you explode the string you get out of youre database, and show only the page where you are, and that will be as default zero because explode starts with zero !)

To show a list of pages you can explode the string ( actually you don't have to cause you already did it ? ) and count it and then it is just make a for loop to show the number list :rolleyes:

I hope i solved you're problem :angrylooking: If you have any questions , then... ask ?:D

#3 dotSilver

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 11 August 2008 - 05:46 PM

RicardoC is right, you need to use the explode and count function. Here's what you need to do.

For this example, we're going to pretend it's a tutorial beign split up into multiple pages. Our tutorial content is called tutorial in the table and our bbcode for a new page is called [nextpage].

Say you're using the $_GET for the id of the tutorial, you'll also need to know what page number the user has requested, you'll do this with the following:

if( !isset( $_GET['page'] ) ){
	$no = 1;
}else{
	$no = (int)$_GET['page'];
	}

So if the url is the following, domain.com/tutorials.php?id=1, then the $_GET['page'] would not be set, so the $no is 1, otherwise it is set, ?id=1&page=2, $no would be 2.

Next step, you get all the tutorial information. You'll then need the following.

$tutorial = explode( '[nextpage]', $r['tutorial'] );

$r['tutorial'] is the tutorial content, [nextpage] is the bbcode to split the tutorial up. What this does is put the tutorial into an array which we've put into $tutorial, say you've got 3 page, the array would be the following:

$tutorial['0'] for page 1, ['1'] for page 2, ['2'] for page 3.

$num = count( $tutorial );

How many pages do we have? We count the number of values we have in the array.

if( $num > 1 ){

If there is more than one page.

$i = 0;
while( $i <= $num ){
	if( $i == $no ){
		print ' <a class="inactive-no">'. $i .'</a>';
	}else{
		print ' <a href="domain.com/tutorial.php?id=1&no='. $i .'">'. $i .'</a> ';
	}
	$i++;
}

This shows the pagination.

To show the relevant page, you use the following

$tutorial[$no - 1]

Because an array starts with 0, and our $no would start with 1, as with page 1, or page 2, we need to decrease it by 1.

You can enhance this code a lot more to suit you're needs, enhance the pagination with style and add a previous and next link (real easy to do).

If you need more help on this, then I can write a full tutorial on it all.

#4 Goon2Goblin

    Young Padawan

  • Members
  • Pip
  • 6 posts

Posted 11 August 2008 - 05:59 PM

Hey thanks guys I really appreciate it.
Each of you make great sense. I don't have time to test it now.. but when I do I'll post my results.

Thanks again :angrylooking:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users