Jump to content

Need pagination without page refresh


moncklee

Recommended Posts

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;

                            }

                            ?>

Link to comment
https://forums.phpfreaks.com/topic/136753-need-pagination-without-page-refresh/
Share on other sites

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.

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.