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!
currently I'm using pagination.but it's only have "Previous page | Next page"
but i want to dispaly it like Page: 1,2,3,4,5,6,... I attahc the code currently i using.pls help me
You should search this forum for a pagination class.. some good ones have been posted.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
He's right. I just posted about the subject a day or two ago and recieved some great input on the subject. The tricky part is trying to maintain the same query results if the query is a multiple field search query after clicking a pagination link. That's what my post was about. There's a few ways to do it, what I believe to be the easiest method is posted in a discussion a few days old, just search my threads by name and you'll find it.
<?
/* Set current, prev and next page */
$page = (!isset($_GET['page'])? 1 : 0;
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 5;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
/* Query the db for total results. You need to edit the sql to fit your needs */
$result = mysql_query("select id from tablename");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$pagination = '';
/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '<a href="index.php?page='.$prev.'">Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '<a href="index.php?page='.$i.'">$i</a>';
}
}
/* Print NEXT link if there is one */
if($page < $total_pages)
{
$pagination .= '<a href="index.php?page='.$next.'">Next</a>";
}
/* Now we have our pagination links in a variable($pagination) ready to print to the page. I pu it in a variable because you may want to show them at the top and bottom of the page */
/* Below is how you query the db for ONLY the results for the current page */
$result=mysql_query("select *
from tablename
LIMIT $from, $max_results ");
while ($i = mysql_fetch_array($result))
{
/* This is where you print your current results to the page */
}
?>