<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Key Ledger</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><?phpinclude 'config.php';include 'opendb.php';echo "<H1>Key Ledger</H1>";// count the keys in the table$keyCountQuery = "SELECT COUNT(id) AS numkeys FROM key_ledger WHERE label IS NOT NULL";$result = mysql_query($keyCountQuery) or die ("Error, key count query failed");list($keyCount) = mysql_fetch_row($result);echo "$keyCount keys<br>";// try to display all data in this many tables// later arrange these tables in 'meta' columns$numTables = 3;// count the number of rows in the key ledger table$rowCountQuery = "SELECT COUNT(id) AS numrows FROM key_ledger";$result = mysql_query($rowCountQuery) or die ("Error, row count query failed");list($rowCount) = mysql_fetch_row($result);// show the whole key ledger table$query = "SELECT id,label,type,serial FROM key_ledger";$result = mysql_query($query);// make as many tables as requested,// but no more than there are rows of datafor ($i=0; $i<min($numTables,$rowCount); $i++) { // reset the number of rows currently printed in this table $printedRows=0; // wrap each table in a named div echo '<div id="table' . "$i" . '">'; echo '<table border="1">'; echo "<td><strong>id</strong></td>" . "<td><strong>label</strong></td>" . "<td><strong>type</strong></td>" . "<td><strong>serial</strong></td>"; // for each table, print an equal portion of the data while(($printedRows < ($rowCount/$numTables)) && (list($id,$label,$type,$serial) = mysql_fetch_row($result)) ) { $printedRows++; echo "<tr>" . "<td>$id</td>" . "<td>$label</td>" . "<td>$type</td>" . "<td>$serial</td>" . // "<td>$printedRows</td>" . "</tr>"; } echo "</table><br>"; // end of this div echo '</div>';}// free query memorymysql_free_result($result);// close the db connectioninclude 'closedb.php';?></body></html>