Well i have script that inserts text a user submits into a database. I want to add a section that lets other users view the text submitted but others in a sort of paged gallery. Im completely stumped on how to make paged content.

For example, it goes into the database, pulls 5 of the most recent entries, then there would be an option to go to page 2, where it would continue.


I've tried searching but no luck, any help is greatly appreciated.

This function should help you get started:

function pageination($count, $nextpage) {
	
	$first_row = 1;
	$col_loop = 3;
	$row_loop = $__num_show / $col_loop;
	$num_pages = ceil($count / __NUM_SHOW);
	
	if($num_pages > 1) {
	
		echo '<div id="line-nav" class="bodycopy">';
	
		echo '<div id="page-count" class="pagecount">';
  		for ($start = 1; $start <= $num_pages; $start++) {
  			if (!isset($_GET['page']) && $start == 1) {
  				echo "|&nbsp;<span class=\"pageOn\">" . $start . "</span>&nbsp;";
  				
  			} else if (isset($_GET['page']) && ($_GET['page'] == $start)) {
  				echo "|&nbsp;<span class=\"pageOn\">" . $start . "</span>&nbsp;";
  				
  			} else {
  				echo '|&nbsp;';
					echo '<a href="' . __SOURCE_URI . '/search-results.php?keywords=' . $_GET['keywords'] . '&page=' . $start . '" class="pageCount">';
  				echo $start . "</a>&nbsp;";
  			}
  		}
  		echo '|';
		echo '</div>';
		echo '<div id="page-info" class="pagecount">';
			echo 'Page ';
			if (!isset($_GET['page'])) { 
				echo "1"; 
			} else { 
				echo $_GET['page']; 
			} 
			echo ' of ' . $num_pages . '&nbsp;&nbsp;|&nbsp;&nbsp;';
  	
			if (($nextpage - 1) != 0) {
				echo '<a href="' . __SOURCE_URI . '/search-results.php?keywords=' . $_GET['keywords'] . '&page=' . ($nextpage - 1) . '">< Previous</a>';
				
			} else {
				echo '<span class="grey-out">< Previous</span>';
			}
			
			echo ' | ';
			
			if (($nextpage + 1) <= $num_pages) {
				echo '<a href="' . __SOURCE_URI . '/search-results.php?keywords=' . $_GET['keywords'] . '&page=' . ($nextpage + 1) . '">Next ></a>';
				
			} else {
				echo '<span class="grey-out">Next ></span>';
			}
		echo '</div>';
		
		echo '</div>';
	}
	
}
This article has been dead for over six months. Start a new discussion instead.