Location: PHPKode > projects > Helpdesk Over Web > how/kb/browseall.php
<?php
// Knowledgebase Browse Page

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

// Set Page Title and Include HTML Header
$page_title = 'HOW - Knowledgebase Browse';
include_once('../includes/header.html');

echo '<H1>Solutions Knowledgebase</H1>';

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

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page * $max_results) - $max_results); 

// Query the database.
$query = "SELECT * FROM knowledgebase ORDER BY category LIMIT $from, $max_results;";		
$records = range(1, 500);
$result = mysql_query($query)
   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 knowledgebase ORDER BY category;"),0); 

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

echo '<H3>Browsing Knowledgebase - All Entries</H3>';
if($num_rows == 0)
	{
	echo "<H4>Sorry - No Entries Found</H4>";
	echo ("<P><B><A HREF='javascript:history.back()'>Back to Previous Page</A></B></P>");
	}
else {
echo '<p>Click on a solution title to view further details and to edit or delete.</P>';
echo ("<TABLE WIDTH='600'><TR><TD WIDTH='250'><b>Category</b></TD><TD width='350'><b>Title</b></TD></TR>");
while($i = mysql_fetch_row($result)) { 
	echo ("<TR>");
	echo ("<TD>$i[1]</TD>");
	echo ("<TD><A HREF='edit.php?entry=$i[0]'>$i[2]</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>";
}
}
echo ("<H5>[ <A HREF='kbadmin.php'>Knowledgebase Administration Menu</A> ]</H5>");
echo ("<H5>[ <A HREF='../index.php'>Main System Menu</A> ]</H5>");

// Include HTML footer.
include_once('../includes/footer.html');
?>
Return current item: Helpdesk Over Web