Reputation: 650
I would like to know how can I insert the pagination for table here. As you will see it is still MYSQL which already depreciated since the owner of the is still working doesn't want to update.
I'm not the developer his system. Can you help me to paginate this part? I'm not familiar with old mysql, since I already started with MYSQLi
#TABLE
if ($userRow['type'] == 'ADMIN') {
$sql = "SELECT * FROM `complaints` ORDER BY `date_modify` DESC, `status` DESC LIMIT 60";
#country
} else {
$sql = "SELECT * FROM `complaints` WHERE `country` in (".$sqlp.") ORDER BY `date_modify` DESC, `status` DESC ";
}
if ($result=mysql_query($sql)) {
$query_num_rows = mysql_num_rows($result);
if($query_num_rows == 0){
echo "<script> alert('No Records Found, Please try again!')</script>";
} else {
while($row=mysql_fetch_array($result))
{
echo "<tbody><tr>";
if($userRow['type']=='ADMIN'){
echo "<td><a href=\"admin-update.php?id=".$row['id']."\">".$row['ticket']."</td>";
} else {
echo "<td><a href=\"followup.php?id=".$row['id']."\">".$row['ticket']."</td>";
}
echo "<td>".$row['c_Fname']." ".$row['c_Lname'];
echo "<td>".$row['section']."</td>";
echo "<td>".$row['topic']."</td>";
echo "<td>".$row['country']."</td>";
echo "<td>".$row['originator']."</td>";
echo "<td>".$row['current']."</td>";
echo "<td>".$row['date_open']."</td>";
echo "<td>".$row['date_modify']."</td>";
if ($row['status'] == 'OPEN') {
$date_o=$row['date_open'];
$date_today=date('Y-m-d h:i A');
$diff = strtotime($date_today) - strtotime($date_o);
$old = $diff/(60*60*24);
echo "<td>".floor($old)."</td>";
} else {
echo "<td> --- </td>";
}
echo "<td>".$row['status']."</td>";
}
}
}
?>
Thanks.
Upvotes: 0
Views: 614
Reputation:
You need to deal with offset and limit in the query:
SELECT column FROM table
LIMIT 10 OFFSET 10
Pass a variable called page
by GET:
HTML
<a href="URL?page=2">Page 2</a>
PHP
"SELECT * FROM complaints
LIMIT 10 OFFSET " . (intval($_GET['page'])-1) * 10
Page 1 => Records between 0 and 10
Page 2 => Records between 11 and 20
Page 3 => Records between 21 and 30
[...]
With page 2, you'll get records between 11 and 20.
Upvotes: 1