Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.