php - Can't get pagination to work in a div -
i have page showing picture of product. underneath have tabs description
, contact details
, comments
. when click on comments
tab comments page loaded div="info"
using jquery
.
products.php:
<html> <head></head> <body> <img src="image.jpg"> <hr> <a id="det"><h3>details</h3></a>  <a id="contact"><h3>contact</h3></a>  <a id="comments"><h3>comments</h3></a> <div id="info"></div> </body> <html>
jquery:
<script> $(document).ready(function(){ $("#comments").click(function(){ $("#info").load("comments.php"); }); }); </script>
the comments.php page below uses pagination comments.
when click on pagination links page refreshes comments.php?page=*
removing div="info"
.how keep comments in div id="info"
when use pagination
?
comments.php:
<?php // 1)set current page $current_page = ((isset($_get['page']) && $_get['page'] > 0) ? (int)$_get['page'] : 1); require 'connect.php'; // 2)get total amount of rows $sql = "select * comments"; $result=mysqli_query($conn,$sql); $totalrows = mysqli_num_rows($result); // offset - calculation skip data want display $results_per_page = 10; $offset = ($current_page-1)*$results_per_page; ?> /*------- comments form -----*/ /*------- comments database ---- */ <?php //here code displaying link , page number. $number_page = $totalrows/$results_per_page; ( $page = 1; $page <= $number_page; $page ++ ) { echo "<a href='comments.php?page={$page}'>{$page}</a>"; } ?>
you know... end problem doing js
making every link inside #info
element update inside it. not sure if need.
$('#info').on('click', 'a', function (e){ e.preventdefault(); $("#info").load($(this).attr('href')); });
Comments
Post a Comment