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
https://forums.phpfreaks.com/topic/206583-page-results-question/
Share on other sites

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.