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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.