1
我已經在我的網站上添加分頁,一切都很好,但每當我點擊下一步它將去同一頁網址/ dataload2.php?page = 0。這是我的PHP代碼,我認爲這是計算或循環中的錯誤,謝謝你的任何幫助。分頁工程,但它不去下一頁
編輯:更多的代碼添加
<?php
include 'conn.php';
$num_rec_per_page=2;
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $num_rec_per_page;
$sql = "SELECT * from crewlist ORDER BY name ASC LIMIT $start_from, $num_rec_per_page";
$result = $conn->query($sql);
?>
和
<?php
$sql = "SELECT * FROM crewlist";
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records/$num_rec_per_page);
echo "<a href='dataload2.php?page=1'>".'|<'."</a> "; // Goto 1st page
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='dataload2.php?page=".$i."'>".$i."</a> ";
};
echo "<a href='dataload2.php?page=$total_pages'>".'>|'."</a> "; // Goto last page
?>
編輯:更新語法
<?php
$sql = "SELECT * FROM crewlist";
$rs_result = mysqli_query($sql); //run the query
$total_records = mysqli_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records/$num_rec_per_page);
echo "<a href='dataload2.php?page=1'>".'|<'."</a> "; // Goto 1st page
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='dataload2.php?page=".$i."'>".$i."</a> ";
};
?>
<?php
echo "<a href='dataload2.php?page=$total_pages'>".'>|'."</a> "; // Goto last page
?>
你在這裏混的MySQL的API。你的連接可能是MySQLi_(看到'$ conn-> query($ sql)'),而另一個則使用'mysql_'。這些不同的API不會互混。 –
將語法更改爲mysqli,仍然不起作用 – swipeales
用您現在使用的新代碼更新您的問題。 –