Ajax分页不起作用

时间:2013-10-23 19:25:27

标签: php jquery ajax pagination

这是我需要帮助分页的代码

Index.php

 setInterval(function() {
         $(document).ready(function() {

                            $.ajax({//create an ajax request to load_page.php
                                type: "GET",
                                url: "products_ajax.php",
                                dataType: "html", //expect html to be returned                
                                success: function(response) {
                                    $("#responsecontainer").html(response);
                                    //alert(response);

product_ajax.php

  <?php
                $per_page = 4;
                $page = 1;
                if (isset($_GET['page'])) {
                    $page = intval($_GET['page']);
                    if ($page < 1)
                        $page = 1;
                }

                $start_from = ($page - 1) * $per_page;   

                $result = mysqli_query($con, "SELECT * FROM gems WHERE end = 1 LIMIT $start_from, $per_page");
                ?>              
<?php

                    while ($row = mysqli_fetch_array($result)) {

                                <td><?php echo $row['name']; ?></td>
                                <td><?php echo $row['description']; ?> </td>

                    ?> 

paginate从这里开始链接

 <?php
                $total_rows = mysqli_query($con, "SELECT COUNT(*) FROM gems");
                $total_rows = mysqli_fetch_row($total_rows);
                $total_rows = $total_rows[0];

                $total_pages = $total_rows / $per_page;
                $total_pages = ceil($total_pages); # 19/5 = 3.8 ~=~ 4

                for ($i = 1; $i <= $total_pages; ++$i) {
                    echo "<a href='products_ajax.php?page=$i'>$i</a> &nbsp;&nbsp;";
                }
                mysqli_close($con);
                ?>

如何使用此代码创建分页工作?当我点击它进入products_ajax页面

0 个答案:

没有答案