Im using vBulletin and Im making a little script which needs to integrate with it. But due to vBulletins lack of PHP plugin support I have to use a client side language to make it work.

So I have this script, its queries a database and has pagination. I want to paginate this process. How would I go about doing it?

<?php
include('includes/config.php');

$sql = "SELECT * FROM list WHERE title LIKE '%$search%'";
//Create a PS_Pagination object
$pager = new PS_Pagination($con,$sql,10,10);
//The paginate() function returns a mysql
//result set for the current page
$rs = $pager->paginate();
//Loop through the result set

while($row = mysql_fetch_assoc($rs)) {
	$title=$row["title"];
	$url=$row["url"];
	$description=$row["description"];
	$lastcrawl=$row["lastcrawl"];    
    
echo '<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="600" align="center">
		<tr> <td class="tcat"><a href="'.rawurldecode($url).'">'.$title.'</a></td> </tr>
		<tr> <td class="alt1">'.$description.'</td> </tr>
		<tr> <td class="alt1">Date Crawled: '.$lastcrawl.'</td> </tr>
	</table>';
}

//Display the navigation

echo '<br /><center>' . $pager->renderFullNav() . '</center>';

?>

EDIT: Im using a pagination class. The class is like 200 lines long so I will post the bit which shows the links for the pagination.

/**
	 * Display the link to the first page
	 *
	 * @access public
	 * @param string $tag Text string to be displayed as the link. Defaults to 'First'
	 * @return string
	 */
	function renderFirst($tag='First') {
		if($this->page == 1) {
			return $tag;
		}
		else {
			return '<a href="'.$this->php_self.'?page=1">'.$tag.'</a>';
		}
	}
	
	/**
	 * Display the link to the last page
	 *
	 * @access public
	 * @param string $tag Text string to be displayed as the link. Defaults to 'Last'
	 * @return string
	 */
	function renderLast($tag='Last') {
		if($this->page == $this->max_pages) {
			return $tag;
		}
		else {
			return '<a href="'.$this->php_self.'?page='.$this->max_pages.'">'.$tag.'</a>';
		}
	}
	
	/**
	 * Display the next link
	 *
	 * @access public
	 * @param string $tag Text string to be displayed as the link. Defaults to '>>'
	 * @return string
	 */
	//function renderNext($tag=' &gt;&gt;') {
	function renderNext($tag=' Next') {
		if($this->page < $this->max_pages) {
			return '<a href="'.$this->php_self.'?page='.($this->page+1).'">'.$tag.'</a>';
		}
		else {
			return $tag;
		}
	}
	
	/**
	 * Display the previous link
	 *
	 * @access public
	 * @param string $tag Text string to be displayed as the link. Defaults to '<<'
	 * @return string
	 */
	//function renderPrev($tag='&lt;&lt;') {
		function renderPrev($tag='Previous') {
		if($this->page > 1) {
			return '<a href="'.$this->php_self.'?page='.($this->page-1).'">'.$tag.'</a>';
		}
		else {
			return $tag;
		}
	}
	
	/**
	 * Display the page links
	 *
	 * @access public
	 * @return string
	 */
	function renderNav() {
		for($i=1;$i<=$this->max_pages;$i+=$this->links_per_page) {
			if($this->page >= $i) {
				$start = $i;
			}
		}
		
		if($this->max_pages > $this->links_per_page) {
			$end = $start+$this->links_per_page;
			if($end > $this->max_pages) $end = $this->max_pages+1;
		}
		else {
			$end = $this->max_pages;
		}
			
		$links = '';
		
		for( $i=$start ; $i<$end ; $i++) {
			if($i == $this->page) {
				$links .= " $i ";
			}
			else {
				$links .= ' <a href="'.$this->php_self.'?page='.$i.'">'.$i.'</a> ';
			}
		}
		
		return $links;
	}
	
	/**
	 * Display full pagination navigation
	 *
	 * @access public
	 * @return string
	 */
	function renderFullNav() {
		return $this->renderFirst().'&nbsp;'.$this->renderPrev().'&nbsp;'.$this->renderNav().'&nbsp;'.$this->renderNext().'&nbsp;'.$this->renderLast();	
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.