Jump to content

Simple Pagination NEXT/PREVIOUS links


codeline

Recommended Posts

I messed around with a simple pagination script I found online. I'm still diving in and breaking it down to try and understand it better but I also was planning to have a "next" and "previous" link instead of just echoing out page numbers.

 

I know I'll have to come up with some $pg+1 or $pg-1 function but how do I find out what $pg is currently on?

 

function showSubmissions(){

$max = 9; // number of news entries per page
$pg = $_GET['pg'];

if(empty($pg))
{
	$pg = 1;
}

$limits = ($pg - 1) * $max; 

//view all the news articles in rows
$q = mysql_query("SELECT * FROM submissions WHERE approved='YES' ORDER BY postdate DESC LIMIT " . $limits . ", $max") or die(mysql_error());
//the total rows in the table
$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM submissions"), 0);	
//the total number of pages (calculated result), math stuff...
$totalpages = ceil($totalres / $max); 



// BEGIN PAGINATION
print '
<div class="paginationList">
	<ul class="pgList">
		<li><img src="images/icon_prevresult.png" title="" alt="" /></li>';

		for($i = 1; $i <= $totalpages; $i++)
		{ 
			//this is the pagination link
			print '<li><a href="submissions.php?pg=' . $i . '">' . $i . ' </a></li>';
		}


print '
		<li><img src="images/icon_nextresult.png" title="" alt="" /></li>
	</ul>
</div>';
// END PAGINATION


// PRINT RESULTS
while($row = mysql_fetch_array($q))
{
	$id = $row['id'];
	$name = stripslashes($row['name']);
	$email = $row['email'];

	print '
	<div class="sub-thumb-wrapper">
		<div class="sub-thumb-user">
			<div class="ps-name"><p class="sub-label">NAME:</p><a href="mailto:' . $email . '">' . $name . '</a></div>
		</div>
	</div>' . "\n";
}
// END PRINT RESULTS

}

Link to comment
https://forums.phpfreaks.com/topic/210840-simple-pagination-nextprevious-links/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.