Jump to content

Need help with page numbers


ROCKINDANO

Recommended Posts

Hello everyone, i am working on a page that displays news topic and would like to have the page numbers at the bottom of the page as links. You know the usual prev (link) then list couple of pages and then next (link).

 

prev - 1 2 3 4 5... next

 

below is the code i have to count my records on my db and display them. but the problem with this is that it displays all of them. page 1 through 50.

 

						$query2 = "SELECT COUNT(title) FROM news";
						$result2 = mysql_query($query2);
						$row = mysql_fetch_row($result2);
						$total_records=$row[0];
						$total_pages = ceil($total_records / 5);


						for ($i=1; $i<=$total_pages; $i++) 
						{								
						if ($i!=1 and $i !=10) { print "<a href='newsevents.php?page={$i}'> " .$i. " </a>"; }
							if ($i==$total_pages)
							{
								print"<p><a href='newsevents.php?page={$i}'> Last Page </a>";
							}
							if ($i==1) 
							{
								print "<p class='floatleft'><a href='newsevents.php?page={$i}'> First Page </a>";
							}


						}


 

Can someone help?

 

 

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.