PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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 in advance
You can set how many numbers you want to appear inbetween. If you have 7 pages and only want 5 digits to appear it will go like... First << 1 2 3 4 ... 8 >> Last
<?php
//Include the PS_Pagination class
include('ps_pagination.php');
//Connect to mysql db
$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('testdb',$conn);
$sql = 'select title from pages';
//Create a PS_Pagination object
$pager = new PS_Pagination($conn, $sql, 8, 3, 'param1=valu1¶m2=value2');
//The paginate() function returns a mysql
//result set for the current page
$rs = $pager->paginate();
//Loop through the result set
while($row = mysql_fetch_assoc($rs)) {
echo $row['title'];
}
//Display the navigation
echo $pager->renderFullNav();
?>
thank you man, thats exactly what i want, but actually i need something simplier, just to add to my original script, if possible
i'l try to understand the script and see if i can get only the lines i need.
if you already know that, and could help, would be awesome
thanks again