在搜索结果分页问题
我想分页的搜索结果,这是我使用查找从用户的体形的搜索查询的代码。 我得到搜索结果分页,但是当我点击的搜索结果的第二页就说明那些项目未定义指数为...虽然通过教程走后,我已经看到了使用$ _GET代替$ _POST,这样做也CHANE没有改善后在结果
由于我是新来这个PHP代码,你们可以帮助或指导我在正确的方向? /////////////test.php//////////////////
mysqli_report(MYSQLI_REPORT_ERROR); // number of results to show per page $per_page = 2; // figure out the total pages in the database if ($result = $mysqli->query("SELECT * FROM bridegroom where Gender like '%$Name%' and Castest like'%$caste%' and Location like '%$location%' order by AGE")) { if ($result->num_rows != 0){ $total_results = $result->num_rows; // ceil() returns the next highest integer value by rounding up value if necessary $total_pages = ceil($total_results / $per_page); if (isset($_GET['page']) && is_numeric($_GET['page'])) { $show_page = $_GET['page']; if ($show_page > 0 && $show_page <= $total_pages) { $start = ($show_page -1) * $per_page; $end = $start + $per_page; } else { $start = 0; $end = $per_page; } } else { $start = 0; $end = $per_page; } // display pagination echo "<p> <b>View search results:</b> "; for ($i = 1; $i <= $total_pages; $i++) { if (isset($_GET['page']) && $_GET['page'] == $i) { echo $i . " "; } else { echo "<a href='test.php?page=$i'>$i</a> "; } } echo "</p>"; // display data in table // loop through results of database query, displaying them in the table for ($i = $start; $i < $end; $i++) { // make sure that PHP doesn't try to show results that don't exist if ($i == $total_results) { break; } // find specific row $result->data_seek($i); $row = $result->fetch_row(); // echo out the contents of each row into a table echo ("Name:$row[1]<br><span class=\"old\"> Age:$row[4]</span><br><span class=\"sold\">Caste:$row[5]</span><br><span class=\"old\">Location:</span><span class=\"sold\">$row[6]</span><br><br>"); } // close table> } else { echo "No results to display!"; } } // error with the query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); // display pagination echo "<p> <b>Your search results:</b> "; for ($i = 1; $i <= $total_pages; $i++) { if (isset($_GET['page']) && $_GET['page'] == $i) { echo $i . " "; } else { echo "<a href='test.php?page=$i'>$i</a> "; } } echo "</p>"; ?>