我試圖2個月此代碼我嘗試修改輸出限制分頁 但對我不起作用每次如何限制從Mysqli搜索這個代碼的分頁php?
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$strKeyword = null;
if (isset($_POST["txtKeyword"])) {
$strKeyword = $_POST["txtKeyword"];
}
if (isset($_GET["txtKeyword"])) {
$strKeyword = $_GET["txtKeyword"];
}
?>
include('condb.php');
$sql = "SELECT *FROM an_files WHERE (f_episode LIKE '%" . $strKeyword . "%' or f_name LIKE '%" . $strKeyword . "%')";
$query = mysqli_query($con, $sql);
$num_rows = mysqli_num_rows($query);
$per_page = 5; // Per Page
$page = 1;
if (isset($_GET["Page"])) {
$page = $_GET["Page"];
}
$prev_page = $page - 1;
$next_page = $page + 1;
$row_start = (($per_page * $page) - $per_page);
if ($num_rows <= $per_page) {
$num_pages = 1;
} else if (($num_rows % $per_page) == 0) {
$num_pages = ($num_rows/$per_page);
} else {
$num_pages = ($num_rows/$per_page) + 1;
$num_pages = (int) $num_pages;
}
$row_end = $per_page * $page;
if ($row_end > $num_rows) {
$row_end = $num_rows;
}
$sql .= "ORDER BY f_date DESC LIMIT $row_start ,4 ";
$query = mysqli_query($con, $sql);
<form class="form-search" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
<table border="0" align="right" width="100%">
<tr>
<td style="border: hidden; text-align: right">
<input placeholder="Searth" type="text"
class="input-medium search-query" name="txtKeyword" id="txtKeyword">
<button type="submit" class="btn">Search</button>
</td>
</tr>
</table>
</form>
<div class="pagination">
<?php
if ($prev_page) {
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&txtKeyword=$strKeyword'><< Back</a> ";
}
for ($i = 1; $i <= $num_pages; $i ++) {
if ($i != $page) {
echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$strKeyword'>$i</a> ";
} else {
echo "<a class='active'><b> $i </b></a>";
}
}
if ($page != $num_pages) {
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&txtKeyword=$strKeyword'>Next>></a> ";
}
?>
</div>
這一點出1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
我想輸出1 2 3 4 5 6 7 8 9 10 ... 20
我怎麼能修改此代碼謝謝
你能完整修改這段代碼嗎?我真的不知道這很難工作 – Comingsoon