moncklee Posted December 12, 2008 Share Posted December 12, 2008 Hello All! I'm a newbie to PHP and MySQL and have really appreciated the information available on this forum - it has helped to produce the following code, which works but every time I click previous or next, the whole page refreshes. I would like to have this feature embedded with tips changing without the whole page refreshing, but I'm not sure how to go about it. Any suggestions would be most welcomed!!! Thanks! /* Set current, prev and next page */ $page = (!isset($_GET['page']))? 1 : $_GET['page']; $prev = ($page - 1); $next = ($page + 1); /* Max results per page */ $max_results = 1; /* 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 tipID from tips"); $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.'"> <img id="larrow" src="images/leftarrow.jpg" alt="Previous Energy Tip" width="32" height="32"></a> '; } /* Print NEXT link if there is one */ if($page < $total_pages) { $pagination .= '<a href="index.php?page='.$next.'>"<img id="rarrow" src="images/rightarrow.jpg" alt="Next Energy Tip" width="32" height="32"></a>'; } $result=mysql_query("select * from tips LIMIT $from, $max_results "); while ($i = mysql_fetch_array($result)) { echo '<div id="tip">'.$i['tip']."</div><br>"; echo $pagination; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/136753-need-pagination-without-page-refresh/ Share on other sites More sharing options...
jordanwb Posted December 12, 2008 Share Posted December 12, 2008 You would need Ajax to do that. Quote Link to comment https://forums.phpfreaks.com/topic/136753-need-pagination-without-page-refresh/#findComment-714212 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 You're going to need to check out some ajax if you want to do this. Remember php is server-side, your browser is client side Quote Link to comment https://forums.phpfreaks.com/topic/136753-need-pagination-without-page-refresh/#findComment-714213 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 You're going to need to check out some ajax if you want to do this. Remember php is server-side, your browser is client side Just in case that not register with you, AJAX is client side... phpfreaks AJAX board is not very active, you may want to find a more dedicated community for getting help. Quote Link to comment https://forums.phpfreaks.com/topic/136753-need-pagination-without-page-refresh/#findComment-714214 Share on other sites More sharing options...
Flames Posted December 12, 2008 Share Posted December 12, 2008 i found one of these earlier today actually http://www.dynamicdrive.com/dynamicindex17/virtualpagination.htm so i guess your in luck. Quote Link to comment https://forums.phpfreaks.com/topic/136753-need-pagination-without-page-refresh/#findComment-714218 Share on other sites More sharing options...
moncklee Posted December 13, 2008 Author Share Posted December 13, 2008 Thanks for the comments. I will check out Ajax and the link (thanks Flames). Happy Holidays! Quote Link to comment https://forums.phpfreaks.com/topic/136753-need-pagination-without-page-refresh/#findComment-714721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.