Tutorial Categories
» PHP
» PHP User System
» Web Development
» Javascript
» Cascading Style Sheets
» HTML
» Adobe Photoshop
» Adobe Dreamweaver
» Adobe Fireworks
» Microsoft Windows
» Microsoft Office
» Apple
» Linux
Partners
» How To Build A Solar Panel » Affordable Web Hosting » How to make a website » Tech Product Reviews » Web Hosting Reviews » Buy Website Traffic » Linux Training » Mac Pro Memory » Dating » EducationWarning: file() [function.file]: URL file-access is disabled in the server configuration in /home/techt/public_html/index.php on line 203
Warning: file(http://www.tucows.no/external.asp) [function.file]: failed to open stream: no suitable wrapper could be found in /home/techt/public_html/index.php on line 203
Warning: Invalid argument supplied for foreach() in /home/techt/public_html/index.php on line 205
So the first thing we need to do, is to start PHP, get our class file and start the class.
Our class is being stored in the variable, $tut. Now we need to check to see if ID is set, if not, then we show an error.
If is not set, ID (must be integer), then show error, else, we get ID into a variable.
We now refer back to our class and get the tutorial requested.
Now I'm not going to explain this next bit, since it's already explained in the comments.
Now we count the number of components in the array, so we can get the number of pages.
This next bit checks to see if a page is set or not.
If it isn't, then we need to make page as 1.
Otherwise it is set, so we can make it into a variable while still making sure it's an integer.
Now that we got everything, let's show the tutorial information.
That's just how I've done mine in the example, you can change it to your liking. This next bit of code refers back to the pagination, and actually shows our pages (if there is more than one page, remember?)
So we send the number of pages, the page we're on, and the ID of the tutorial. Now we can show the actual tutorial.
Remember that arrays start with 0, so page 1 in the array is actually 0, so we take 1 away (Well it wouldn't look good saying Page 0 would it?). Almost done, three more lines to do, first one, we show the pagination again, so now we have the pagination above and below the tutorial, then we end the else statement (if ID is set), and end php.
Well that's it, that's a fairly advanced pagination on a single field in a query.
<?php
require_once('page.php');
$tut = new tutorials;Our class is being stored in the variable, $tut. Now we need to check to see if ID is set, if not, then we show an error.
<?php //If ID isn't set show error
if( !isset( (int)$_GET['id'] ) ){
print 'No ID is set.';
}else{If is not set, ID (must be integer), then show error, else, we get ID into a variable.
<?php //Get the ID of the tutorial $id = (int)$_GET['id'];
We now refer back to our class and get the tutorial requested.
<?php $sql = $tut->get_tut($id); $r = mysql_fetch_array($sql);
Now I'm not going to explain this next bit, since it's already explained in the comments.
<?php //Split up the tutorial
//Explode splits a string on a string sperator and returns an array of components
//In this sense, we split it up where [ nextpage ] is present.
//You will need to take out the spaces between [ n and e ] below.
$content = explode('[ nextpage ]', $r['content']);Now we count the number of components in the array, so we can get the number of pages.
<?php //We now count the number of components in the array. $num = count( $content );
This next bit checks to see if a page is set or not.
<?php //If no page is set.
if( !isset( $_GET['page'] ) ){If it isn't, then we need to make page as 1.
<?php //Then set page as 1 $page = 1;
Otherwise it is set, so we can make it into a variable while still making sure it's an integer.
<?php }else{
//Otherwise page is what is set
$page = (int)$_GET['page'];
}Now that we got everything, let's show the tutorial information.
<?php print '<div class="top"> <div class="title">'. $r['title'] .'</div> <div class="info">Posted on '. $r['postdate'] .' by '. $r['username'] .'</div> <div class="pages"><strong>Total Pages:</strong> '. $num .'</div> </div>';
That's just how I've done mine in the example, you can change it to your liking. This next bit of code refers back to the pagination, and actually shows our pages (if there is more than one page, remember?)
<?php $tut->pagination($num, $page, $id);
So we send the number of pages, the page we're on, and the ID of the tutorial. Now we can show the actual tutorial.
<?php print $content[$page - 1];
Remember that arrays start with 0, so page 1 in the array is actually 0, so we take 1 away (Well it wouldn't look good saying Page 0 would it?). Almost done, three more lines to do, first one, we show the pagination again, so now we have the pagination above and below the tutorial, then we end the else statement (if ID is set), and end php.
<?php $tut->pagination($num, $page, $id); } ?>
Well that's it, that's a fairly advanced pagination on a single field in a query.