Jump to content

page results question


fael097

Recommended Posts

hi!

i have this real simple code to display result pages:

<?php
include("includes/connect_db.php");

if (isset($_GET["page"]))
{
$page=$_GET["page"];
}
else
{
$page=1;
}

$start_from=($page-1)*10; 
$sql="SELECT * FROM test ORDER BY name ASC LIMIT $start_from, 10"; 
$rs_result=mysql_query($sql,$conn_db); 
?> 

<table>
<tr><td>Name</td><td>Surname</td></tr>

<?php 
while ($row=mysql_fetch_array($rs_result))
{ 
echo '
            <tr>
		<td>'.$row["name"].'</td>
            <td>'.$row["surname"].'</td>
            </tr>
';
}
?>

</table>

<?php
$sql="SELECT COUNT(name) FROM test"; 
$rs_result=mysql_query($sql,$conn_db); 
$row=mysql_fetch_row($rs_result); 
$total_records=$row[0]; 
$total_pages=ceil($total_records/10); 

for ($i=1; $i<=$total_pages; $i++) 
{ 
if($page==$i)
{
	echo "<b>$i </b>";
}
else
{
	echo "<a href='?page=".$i."'>".$i."</a> ";
}
}
?>

you can see it in action here: http://teapot.justca.me/test.php

but the problem is that it displays how many pages there will be, and i need to display a maximum of 5 pages (1 2 3 4 5 ... [next] ), then a link to show the next set of 5 pages (the 3 dots, would return something like [previous] ... 6 7 8 9 10 ... [next])

 

and i have no clue how to do that. any help is highly appreciated!

thanks

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.