Location: PHPKode > projects > Helpdesk Over Web > how/users/useradmin.php
<?php

// Users Database Admin

// Include Configuration File
require_once ('../includes/config.inc'); 

// Set the page title and include the HTML header.
$page_title = 'Helpdesk Over Web - Users Database';
include ('../includes/header.html');

// Get selected sort order from header.
$sortorder = $HTTP_GET_VARS['sortorder'];

// Connect to Database
require_once ('../includes/mysql_connect.php');

// Define pagination variables.
if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

// Define the number of results per page 
$max_results = 10; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page * $max_results) - $max_results); 
	
// Execute query to retrieve user details.
$sql = "SELECT * FROM users ORDER BY '$sortorder' LIMIT $from, $max_results;";
$records = range(1, 500);
$result = mysql_query($sql)
   or die("Invalid query: " . mysql_error());
$num_rows = mysql_num_rows($result);

// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users ORDER BY '$sortorder';"),0); 

// Calculate total number of pages needed to display.
$total_pages = ceil($total_results / $max_results);

// Output query results in a table.
echo ("<H1>Users Database</H1><H3>Administration Screen</H3><P>Click a Login name to view/amend the user profile. Click on a column heading to change sort order.</P>");
echo ("<TABLE WIDTH='600'><TR><TD WIDTH='75'><b><A HREF='useradmin.php?sortorder=UserID'><FONT COLOR=#000000>User ID</FONT></A></b></TD><TD><b><A HREF='useradmin.php?sortorder=UserSurname'><FONT COLOR=#000000>Surname</FONT></A></b></TD><TD><b><A HREF='useradmin.php?sortorder=UserFirstname'><FONT COLOR=#000000>First Name</FONT></A></b></TD><TD><B><A HREF='useradmin.php?sortorder=Dept'><FONT COLOR=#000000>Dept</FONT></A></b></TD><TD><B><A HREF='useradmin.php?sortorder=Site'><FONT COLOR=#000000>Site</FONT></A></b></TD><TD><B>Tel</b></TD></TR>");
while($i = mysql_fetch_row($result)) { 
	echo ("<TR>");
	echo ("<TD><A HREF='userdetail.php?selecteduser=$i[0]'>$i[0]</TD>");
	echo ("<TD>$i[2]</TD>");
	echo ("<TD>$i[1]</TD>");
	echo ("<TD>$i[3]</TD>");
	echo ("<TD>$i[4]</TD>");
	echo ("<TD>$i[5]</TD>");
	}
echo ("</TABLE>");
echo "<P><b>Displaying $max_results results per page.</b></P>";
// Build Previous Link 
echo "<P><b>Page</b>: ";if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href='useradmin.php?page=$prev&sortorder=UserSurname'><</a>&nbsp;"; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i&nbsp;"; 
        } else { 
            echo "<a href='useradmin.php?page=$i&sortorder=UserSurname'>$i</a>&nbsp;"; 
    } 
} 

// Build Next Link 
if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href='useradmin.php?page=$next&sortorder=UserSurname'>></a>"; 
	echo "</P>";
}

echo ("<H4><A HREF='newuser.php'>Create New User</A></H4>");
echo "<P>[ <A HREF='../index.php'>Main Menu</A> ]</P>";
// Include standard HTML footer
include ('../includes/footer.html');
?>
Return current item: Helpdesk Over Web