Location: PHPKode > projects > Helpdesk Over Web > how/assets/assetadmin.php
<?php

// Asset Database Admin

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

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

// 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 = 15; 

// 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 assets ORDER BY Category, AssetTag 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 assets ORDER BY Category, AssetTag;"),0); 

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

// Output query results in a table.
echo ("<H1>Asset Database</H1><H3>Administration Screen</H3><P>Click an Asset Tag to view/amend the asset record. </P>");
echo ("<TABLE WIDTH='600'><TR><TD><b>Asset Tag</b></TD><TD><b>Category</b></TD><TD><b>Manufacturer</b></TD><TD><b>Model</b></TD><TD><b>User</b></TD></TR>");
while($i = mysql_fetch_row($result)) { 
	echo ("<TR>");
	echo ("<TD><A HREF='assetdetail.php?selectedasset=$i[0]'>$i[0]</A></TD>");
	echo ("<TD>$i[1]</TD>");
	echo ("<TD>$i[2]</TD>");
	echo ("<TD>$i[3]</TD>");
	echo ("<TD><A HREF='/how/users/userdetail.php?selecteduser=$i[6]' TARGET='new'>$i[6]</A></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=\"".$_SERVER['PHP_SELF']."?page=$prev\"><</a>&nbsp;"; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i&nbsp;"; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a>&nbsp;"; 
    } 
} 

// Build Next Link 
if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">></a>"; 
	echo "</P>";
}

// Nav Links
echo ("<H4><A HREF='newasset.php'>Create New Asset</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