dongpangfu6322 2015-01-03 14:07
浏览 47

“下一步”按钮不会刷新下一个25个结果的页面

I have the code below and am trying to get the next 25 results from my sql table to appear on page. However, whenever I click the next button, no information is displayed. I have my offset = ($page - 1) * $items_per_page......I'm struggling to figure this out as it seems so simple compared the other code I've written, but is proving to be very elusive to me....any assistance would be greatly appreciated. My primary issue is that the next link does not provide the next 25 results and I'm unable to determine why and how to correct.

                            echo "<h3 style='text-align:center;'>Welcome to the Exchange Portal,&nbsp;" . $row['name'] . "!&nbsp;</h3>";


                            $items_per_page = 25;


                            $sql_count = "SELECT pin, title, title2, email, phone FROM crown_acura";
                            $result_cnt = mysqli_query($conn, $sql_count);

                            if(false === $result_cnt) {
                                throw new Exception('Query failed with: ' . mysqli_error());
                                } else {
                                   $row_count = mysqli_num_rows($result_cnt);
                                   // free the result set as you don't need it anymore
                                   //mysqli_free_result($result_cnt);
                                }

                                echo $row_count;
                                echo "&nbsp;";

                                if (!isset($_GET['Page'])) {
                                    $Page = 1;
                                } else {
                                    $Page = $_GET['Page'];
                                }
                                echo $page;
                                echo "&nbsp;";

                                $page_count = 0;
                                if (0 === $row_count) {  
                                    // maybe show some error since there is nothing in your table
                                } else {
                                  // determine page_count
                                   $page_count = (int)ceil($row_count / $items_per_page);
                                   // double check that request page is in range
                                   if($page > $page_count) {
                                        // error to user, maybe set page to 1
                                        $page = 1;
                                   }
                                }
                                echo "&nbsp;";
                                echo $page_count;
                                echo "&nbsp;";
                                echo $items_per_page;

                                $offset = ($page-1)*$items_per_page;


                                //echo $paging_info;
                                //echo "&nbsp;";
                                echo "<br />";

                            //Query for displaying results
                            $list_sql = "SELECT pin, title, title2, email, phone FROM crown_acura LIMIT $offset, $items_per_page";
                            $result_query = $conn->query($list_sql);

                                //Table for displaying query results
                                echo "<table class='verify'>";
                                echo "<tr >";
                                echo "<td><h3>Name</h3></td><td>&nbsp;</td><td><h3>E-mail</h3></td><td><h3>Phone</h3></td>";
                                echo "</tr>";
                                for($i = 1; $i<= $page_count; $i++) {
                                    if ($result_query->num_rows > 0) {
                                        // output data of each row
                                        while($row3 = mysqli_fetch_array($result_query)) {
                                            echo "<tr>";
                                            echo "<td class='dltd2 dlcl'>" . $row3["title"] . "</td><td>" . $row3["title2"] . "</td><td><a href='mailto:" . $row3['email'] . "'>" . $row3["email"] . "</a>&nbsp;</td><td>" . $row3["phone"] . "&nbsp;</td>";
                                            echo "</tr>";   
                                        }
                                    } else {
                                        echo "0 results";   
                                    }
                                }
                                echo "<tr></tr>";


                                $next_page = $page + 1;
                                $last_page = $page - 1;

                                if($paging_info['curr_page'] <= 1) {
                                    echo "<tr>";
                                    echo "<td></td><td colspan='2'><a class='loadlink' href='" . $_PHP_SELF . "'>Next 25</a></td><td></td>";
                                    echo "</tr>";
                                } elseif ($paging_info['curr_page'] < $page_count) {
                                        echo "<tr>";
                                        echo "<td></td><td><a href='" . $_PHP_SELF . "?page=" . $last_page . "'>Prev 25</a></td><td><a href='" . $_PHP_SELF . "?page=" . $next_page . "'>Next 25</a></td><td></td>";
                                        echo "</tr>";
                                        } elseif ($paging_info['curr_page'] === $page_count) {
                                            echo "<tr>";
                                            echo "<td></td><td colspan='2'><a href='" . $_PHP_SELF . "?page=" . $last_page . "'>Prev 25</a></td><td></td>";
                                            echo "</tr>";
                                            }

                                echo "</table>";
                    }
                }
            }
  • 写回答

2条回答 默认 最新

  • douque9815 2015-01-03 14:23
    关注

    Have you tried to run the rendered SQL.

    Output to browser:

    "SELECT pin, title, title2, email, phone FROM crown_acura LIMIT $offset, $items_per_page" 
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度