Jump to content

Pagination


shadowayex

Recommended Posts

I just built a pagination script that I wanted to show you guys to see what you think.Now first I want to explain the system. It grabs data from a database, displays it on the page in different divs ("pages") which contain a certain amount depending on the amount chosen by the scriptor. From there, only one div is show at a time by hiding all the rest. The page could get really slow loading times if there's a huge amount of records, so I'm going to build an alternate, but this version works fine right now:

<?php/*-----Replace this next line with your own connection script-----*/include('PHP_Files/connect.php');/*-----Number of Entries per Page-----*/$pmax = 3;/*------------------------------------*//*------Determine which page to be shown (Default = 1)------*/$pshown = isset($_GET['page']) ? $_GET['page'] : '1';$query = mysql_query('/*Your Query Here*/');$i = 1;$page = 1;/*------Pages------*/while($row = mysql_fetch_array($query)){	if($i == 1)	{		echo '<div';                if($page != $pshown)                {                    echo ' style="height: 0px; visibility: hidden; overflow: hidden;"';                }                echo '>';	}	echo $row['/*Your Column*/'];	if($i == $pmax)	{		echo '</div>';		$i = 0;                $page += 1;	}	$i += 1;}/*----------------------------------------------Make sure the last div is closed by checking the value of $i. If $i is 1, that means that the lastentry fell on the limit and the ending div wasplaced. If not we need to put it.----------------------------------------------*/if($i != 1){    echo '</div>';}/*------Page Links------*/$pnum = mysql_num_rows($query);$pnum /= $pmax;$pnum = ceil($pnum);echo 'Page ';for($i=1; $i<=$pnum; $i++){	echo '<a href="pagination.php?page=' . $i . '">' . $i . '</a> ';}?>

Try it out and tell me what you think.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...