hello, this works fine and can be tweaked to many usages
hope it'll work for you
////first is the include named dbinfo.inc.php
//////
<?
$username="aaaaa";
$password="aaaaaaa";
$database="aaaaaaaa";
$host="aaaaaaa";
?>
///// then is the engine
///allows for number of pages etc....
<?
include("dbinfo.inc.php"

;
?>
<?
$connect = @mysql_connect("$host", "$username", "$password"

;
if (!($connect)) // If no connect, error and exit().
{
echo("<p>Unable to connect to the database server.</p>"

;
exit();
}
if (!(@mysql_select_db($database))) // If can't connect to database, error and exit().
{
echo("<p>Unable to locate the $database database.</p>"

;
exit();
}
if (!($limit)){
$limit = 10;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
$numresults = mysql_query("SELECT business_name, newsletter_name, newsletter_text FROM stories where category like '%ag%". $query ."%' "

;
// the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
if ($numrows == 0){
echo("No results found matching your query - $query"

;
exit();}
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows%$limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
//escape from PHP mode.
?>
<html>
<head>
<title>Search Results for <?=$query?></title>
</head>
<body>
<table width="100%" border="2" bgcolor="#ffffcc">
<tr>
<td align="left" colspan="4">
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>
Page <b><?=$current?></b> of <b><?=$total?></b>
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5"><b>5</b></a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10"><b>10</b></a>
</td>
</tr>
<?
//Go back into PHP mode.
// Now we can display results.
$results = mysql_query("SELECT business_name, newsletter_name, newsletter_text FROM stories where category like '%ag%". $query ."%' ORDER BY business_name ASC LIMIT $page, $limit"

;
while ($data = mysql_fetch_array($results))
{
?>
<tr>
<td width="100% align="top" valign="left"><font color="#cccccc" size="4"><I>AGRICULTURE & FOOD</i></font>
</td></tr>
<tr>
<td width="100%" align="left" valign="top"><font color="#990000" size="3">Business Name</font>: <?=$data["business_name"]?></font></td>
</tr>
<tr>
<td width="100%" align="left" valign="top"><font color="#990000" size="3">Newsletter Name</font>: <?=$data["newsletter_name"]?></font></td>
</tr>
<tr>
<td width="33%" align="left" valign="top"><font color="#990000" size="3">Newsletter</font>: <br>
<?=$data["newsletter_text"]?></font></td>
</tr>
<tr>
<td width="100%" colspan="1">
<?
{ // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\"><align=left><font size=3>Next: Click here to jump to next page</a></font></hr>\n"

;}
?>
</tr>
</td>
<?
}
?>
<align="left">
<?
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n"

;}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b><hr size=5 align=left width=400>$i</b></hr> \n"

;} // If current page don't give link, just text.
else{
echo("<font size=4><a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a></font> \n"

;}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\"><hr size=5 align=left width=400><font size=5>next</a></font></hr>\n"

;}
?>
</table>
</body>
</html>