954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Paged content from database

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.

blindkilla
Newbie Poster
20 posts since Oct 2007
Reputation Points: 10
Solved Threads: 1
 

Try searching for pagination. If you can't find it with that then you aren't looking hard enough.

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

Thanks ill search for that, i just wasnt sure what this was called.

blindkilla
Newbie Poster
20 posts since Oct 2007
Reputation Points: 10
Solved Threads: 1
 

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>';
	}
	
}
Imagn
Newbie Poster
1 post since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You