Кто-нибудь может сказать мне, что не так в этой нумерации страниц. Я пытаюсь сделать нумерацию страниц после каждых 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> ";
}
}
?>
[/ NOEDIT]
Попробуйте это ………. Простая нумерация страниц
<html>
<head>
<style>
#content
{
width: 900px;
margin: 0 auto;
font-family:Arial, Helvetica, sans-serif;
}
.page
{
float: right;
margin: 0;
padding: 0;
}
.page li
{
list-style: none;
display:inline-block;
}
.page li a, .current
{
display: block;
padding: 5px;
text-decoration: none;
color: #8A8A8A;
}
.current
{
font-weight:bold;
color: #000;
}
.button
{
padding: 5px 15px;
text-decoration: none;
background: #333;
color: #F3F3F3;
font-size: 13PX;
border-radius: 2PX;
margin: 0 4PX;
display: block;
float: left;
}
</style>
</head>
<body>
<div id="content">
<?php
$query1=mysql_connect("localhost","root","");
mysql_select_db("contractor_leads",$query1);
$start=0;
$limit=5;
if(isset($_GET['id']))
{
$id=$_GET['id'];
$start=($id-1)*$limit;
}
else
{
$id=1;
}
$query=mysql_query("SELECT * FROM category2 LIMIT $start, $limit");
?>
<table border="1">
<tr>
<th>Name</th>
<th>Device Id</th>
<th>Puppy Count</th>
</tr>
<?php
while($query2=mysql_fetch_array($query))
{
echo "<tr><td>".$query2['parent_child_name']."</td>
<td>".$query2['parent_child_name']."</td>
<td>".$query2['parent_child_name']."</td>
</tr>";
}
echo "</table>";
$rows=mysql_num_rows(mysql_query("SELECT * FROM category2"));
$total=ceil($rows/$limit);
if($id>1)
{
echo "<a href='?id=".($id-1)."' class='button'>PREVIOUS</a>";
}
if($id!=$total)
{
echo "<a href='?id=".($id+1)."' class='button'>NEXT</a>";
}
echo "<ul class='page'>";
for($i=1;$i<=$total;$i++)
{
if($i==$id) { echo "<li class='current'>".$i."</li>"; }
else { echo "<li><a href='?id=".$i."'>".$i."</a></li>"; }
}
echo "</ul>";
?>
</div>
</body>
</html>
Других решений пока нет …