Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Multi Page Support For Staff List
Browse files Browse the repository at this point in the history
  • Loading branch information
cammygames committed Mar 23, 2015
1 parent 45d8e02 commit f25870f
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions views/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// create a database connection, using the constants from config/db.php (which we loaded in index.php)
$db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

$page_rows = results_per_page;

// change character set to utf8 and check it
if (!$db_connection->set_charset("utf8")) {
$db_connection->errors[] = $db_connection->error;
Expand Down Expand Up @@ -93,15 +95,41 @@
<?php
if (!$db_connection->connect_errno)
{
if (!(isset($_POST['pagenum'])))
{
$pagenum = 1;
}
else
{
$pagenum = $_POST['pagenum'];
}

$sql = "SELECT * FROM `users`;";

$result_of_query = $db_connection->query($sql);
$rows = mysqli_num_rows($result_of_query);

if (!empty($_POST))
$last = ceil($rows/$page_rows);

if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

if (isset($_POST['searchText']))
{
$searchText = $_POST['searchText'];
$sql = "SELECT * FROM `users` WHERE `user_name` LIKE '%".$searchText."%' ;";
$sql = "SELECT * FROM `users` WHERE `user_name` LIKE '%".$searchText."%' ".$max." ;";
}
else
{
$sql = "SELECT * FROM `users`;";
$sql = "SELECT * FROM `users` ".$max.";";
}

$result_of_query = $db_connection->query($sql);
Expand All @@ -119,6 +147,39 @@
echo "</form></td>";
echo "</tr>";
};
echo "</tbody></table>";
echo "<table><thead>";
echo "<br>";
if ($pagenum == 1){}
else
{
echo "<th><form method='post' action='".$_SERVER['PHP_SELF']."' name='pagenum'>";
echo "<input id='pagenum' type='hidden' name='pagenum' value='1'>";
echo "<input type='submit' value=' <<-First '>";
echo "</form></th>";
$previous = $pagenum-1;
echo "<th><form style='float:right;' method='post' action='".$_SERVER['PHP_SELF']."' name='pagenum'>";
echo "<input id='pagenum' type='hidden' name='pagenum' value='".$previous."'>";
echo "<input type='submit' value=' <-Previous '>";
echo "</form></th>";
}
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last) {}
else
{
$next = $pagenum+1;
echo "<th><form method='post' action='".$_SERVER['PHP_SELF']."' name='pagenum'>";
echo "<input id='pagenum' type='hidden' name='pagenum' value='".$next."'>";
echo "<input type='submit' value=' Next -> '>";
echo "</form></th>";
echo " ";
echo "<th><form method='post' action='".$_SERVER['PHP_SELF']."' name='pagenum'>";
echo "<input id='pagenum' type='hidden' name='pagenum' value='".$last."'>";
echo "<input type='submit' value=' Last ->> '>";
echo "</form></th>";
}
echo "</thead></table>";

}
else
{
Expand Down

0 comments on commit f25870f

Please sign in to comment.