Jump to content

PHP Paging Help


abch624

Recommended Posts

Hi Guys,

 

I have my code for paging which works perferctly fine but displays all the page numbers. i.e. <- 1 2 3 4 5 6 7 8 9 10 -> what I am looking to do is <- 1 2 ... 9 10 ->.

 

I have my code bellow. please have a look and let em know where I can put this functionality.

 

Guys your help will be appreciated.

 

Cheers - Zahid

 

<?php
$page_name=""; //  If you use this code with a different page ( or file ) name then change this 

if (isset($_GET['review'])) {
	$review=$_GET['review'];
}
else {
	$review = 0;
}

$eu = ($review - 0); 
$limit = 5;                                 // No of records to be shown per page.
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 

/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$query2="SELECT * FROM review";
$result2=mysql_query($query2);
$nume=mysql_num_rows($result2);

////////////// Now let us review executing the query with variables $eu and $limit  set at the top of the page///////////
$query=" SELECT * FROM review limit $eu, $limit ";
$result=mysql_query($query);
echo mysql_error();

//////////////// Now we will display the returned records in side the rows of the table/////////
while($row = mysql_fetch_array($result)) {

		echo 'The content here';
}
echo '
<div style="float:right;">
	<div class="middel_small_left" style="overflow:auto;">
		<div class="top_small_left">
			<div style="float:right; padding-right:30px;">
			</div>
		</div>
		<div style="padding-left:20px; overflow:auto;">';
		////////////////////////////// End of displaying the table with records ////////////////////////
		/////////////////////////////// 
		if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging
			/////////////// review the bottom links with Prev and next link with page numbers /////////////////
			echo '
				<div style="float:left; width:440px; padding-left:15px; padding-top:10px; padding-bottom:10px;">
					<table align = "center" width="200">
						<tr>
							<td  align="left" width="200">';
			//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
			if($back >=0) { 
				print '
					<a id="prevLink" onclick="reviewAjax('.$back.');" href="#">
						<img alt="previous" src="/images/interface/back.png"/>
					</a>'; 
			} 
			//////////////// Let us display the page links at  center. We will not display the current page as a link ///////////
			echo "</td><td align=center width='30%'>";
			$i=0;
			$l=1;
			for($i=0;$i < $nume;$i=$i+$limit){
				if($i <> $eu){
					echo '
						<a style="padding-right:2px;" id="thisLink" onclick="reviewAjax('.$i.');" href="#">
							<font face="Verdana" size="3">'.$l.'</font>
						</a>';
				}
				else { 
					echo "
						<font face='Verdana' size='4' color=blue>$l</font>";
				}        /// Current page is not displayed as link and given font color red
				$l=$l+1;
			}
			echo "</td><td  align='right' width='30%'>";
			///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
			if($this1 < $nume) { 
				print '
					<a id="nextLink" onclick="reviewAjax('.$next.');" href="#">
						<img alt="next" src="/images/interface/next.png"/>
					</a>';
			} 
			echo "</td></tr></table></div>";
		}// end of if checking sufficient records are there to display bottom navigational link. 
		echo '
		</div>
		<div class="bottom_small_left"></div>
	</div>
</div>';
?>

Link to comment
https://forums.phpfreaks.com/topic/162587-php-paging-help/
Share on other sites

  • 2 weeks later...

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.