from a MySQL database.
require( "mysqlcheck.inc"); /* Check the mysql daemon */
/*
This is a template for a script that will return the next n records from a MySQL
database query. It uses the LIMIT option in the MySQL SELECT syntax
Data Dictionary
* $fgcolour Foreground colour of document
* $bgcolour Background colour of document
* $leftarr Image to use for Previous image
* $rightarr Image to use for Next image
* $database Database to query
* $table Table to query
* $lower Lowest number of the records currently on display
* $upper Highest number of the records currently on display
* $NUM_RECS Number of records to be diplayed per page
* $offset Use for OFFSET value in 'SELECT' statement
* $searchon Field to be searched on
* $searchfor Value to be searched for
*/
function formDropDown($name,$value,$labels) {
$html = "\n";
return $html;
}
/* Some attributes that can be changed */
/* Set fore and background colour values */
$fgcolour = "#009999";
$bgcolour = "#000033";
/* And the images to use for arrows. */
$leftarr = "/gifs/cyan_left.gif";
$rightarr = "/gifs/cyan_right.gif";
/* Name of the database and table to use for the query */
$database = "database";
$table = "table";
?>
Title
Search
Search for references.
/* First time through on a new search $offset should be zero,
$lower should be one and $upper should be $NUM_RECS
*/
if(empty($lower)):
$lower = 1;
endif;
if(empty($upper)):
$upper = $NUM_RECS;
endif;
if(empty($offset)):
$offset = 0;
endif;
if(!empty($next_x)): /* The Next button has been selected */
$lower += $NUM_RECS;
$upper += $NUM_RECS;
$offset += $NUM_RECS;
endif;
if(!empty($prev_x)): /* The Previous button has been selected */
$lower -= $NUM_RECS;
$upper -= $NUM_RECS;
$offset -= $NUM_RECS;
endif;
/* echo "Offset: " . $offset . ": Lower: " . $lower . ": Upper: " . $upper . "
"; */
switch($search):
case "Search":
/* Build the query string from the data passed in. */
$NUM_RECS = intval($NUM_RECS);
$query = "SELECT * FROM " . $table . " WHERE " . $searchon;
$query .= " LIKE '%" . $searchfor . "%' LIMIT " . ($offset != 0 ? "$offset, " : "$NUM_RECS");
/* Countquery gets the number of records that are be retuned by the 'real' query */
$countquery = "SELECT count(*) AS numrows FROM " . $table. " WHERE " . $searchon;
$countquery .= " LIKE '%" . $searchfor . "%'";
$countresult = mysql_db_query($database, $countquery);
$countrow = mysql_fetch_array($countresult);
$result = mysql_db_query($database, $query);
$numrows = intval($countrow[0]);
?>
switch($numrows):
case 0:
echo "There were no matches to your search for " . $searchfor;
echo " in " . $searchon . ". You may wish to try again with a different search phrase.";
break;
default:
/* (!empty($offset) ? $lower = ($offset - $NUM_RECS) + 1 : $lower = 1);
$upper = $offset + $NUM_RECS; */
echo "";
if($numrows <= $NUM_RECS):
echo "Displaying all ". $numrows;
else:
echo "Displaying matches " . $lower . " to " . ($upper > $numrows ? $numrows : $upper). "
of " . $numrows;
endif;
echo " matches for '" . $searchfor . "'";
while($row = mysql_fetch_array($result)):
?>
endwhile;
break;
endswitch; /* Numrows */
break;
default: /* No search - throw up the search entry form */
endswitch; /* Search */
if($numrows > $NUM_RECS):
?>
endif;
?>