有人可以告訴我這個分頁有什麼問題。我試圖在每10條記錄後進行分頁,但失敗。相反,我在同一時間看到所有記錄,而不是分頁。我在這裏錯了。面對分頁問題
查看用戶文件
<form action="tuser.php" method="GET">
<table>
<tr>
<td>Here You get the Table View of Data</td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Total Number of User"/></td>
</tr>
</form>
編碼文件
<?php
$con = mysqli_connect("localhost","root","","testsite");
if(!$con)
{
die("Could not connect: ".mysqli_error());
}
/* if(!(isset($pagenum)){
$pagenum = 1;
}
*/
$view = $_GET['submit'];
if(isset($_GET['submit']))
{
$stbl = "SELECT * FROM `register`";
$ssql = mysqli_query($con,$stbl);// OR die("Query Error: ".mysqli_error());
$num = mysqli_num_rows($ssql);
echo $num;
$pagerow = 10;
$total = ceil($num/$pagerow);
/* $pagenum = $total;
/* if($pagenum < 1){
$pagenum = 1;
}
else {
$pagenum = $total;
}*/
$max = 'limit ' .($pagenum - 1) * $pagerow .',' .$pagerow;
$ussql = mysqli_query($con, "SELECT * FROM `register` LIMIT '$max'");
echo "<table border=5 table style=margin-top: 252px; font-size: larger; font-style: oblique; bgcolor=#05fa8c>
<tr>
<td width=10% height= 10%><b>User Name:</b></td>
<td width=10% height= 10%><b>First Name:</b></td>
<td width=10% height= 10%><b>Last Name:</b></td>
<td width=10% height= 10%><b>Password:</b></td>
<td width=10% height= 10%><b>Email:</b></td>
<td width=10% height= 10%><b>Role Type:</b></td>
<td width=10% height= 10%><b>About:</b></td>
<td width=10% height= 10%><b>Edit<b></td>
<td width=10% height= 10%><b>Delete</b></td>
</tr>";
while($row = mysqli_fetch_array($ssql))
{
$rid = $row['id'];
$uname = $row['username'];
$fname = $row['firstname'];
$lname = $row['lastname'];
$pwd = $row['password'];
$emal = $row['email'];
$rol = $row['role'];
$abt = $row['profession'];
echo "<tr>
<td width=10% height= 10%>$uname</td>
<td width=10% height= 10%>$fname</td>
<td width=10% height= 10%>$lname</td>
<td width=10% height= 10%>$pwd</td>
<td width=10% height= 10%>$emal</td>
<td width=10% height= 10%>$rol</td>
<td width=10% height= 10%>$abt</td>
<td width=10% height= 10%><a href=edit_records.php?id=$rid>Edit </a></td>
<td width=10% height= 10%><a href=delete.php?id=$rid>Delete</a></td>
</tr>";
}
echo"</table>";
echo " --Page $pagenum of $max-- <p>";
if($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
}
if($pagenum == $max)
{
}
else
{
$next = $pagenum + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$max'>Last ->></a> ";
}
}
?>
錯了,因爲什麼呢?它會出錯? – 2014-11-21 09:59:59
沒有任何錯誤,但所有記錄都顯示在一個頁面中。有些時候我面臨未定義的索引:提交錯誤 – 2014-11-21 10:03:30