<?php
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
Written by David Robley July 1998
Comments, improvements etc to webmaster@www.nisu.flinders.edu.au
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
*/
/* formDropDown - create an HTML <SELECT> - By John Bryant
* vars: $name - the form variable NAME
* $value - the SELECTED option
* $labels - assoc. array, list of values=>labels
* returns: string, HTML (i.e. for use in echo or print statement)
*/
function formDropDown($name,$value,$labels) {
$html = "<SELECT NAME=\"$name\">\n";
$key = key($labels);
while($key != "") {
if ($key == $value) {
$selected = "SELECTED";
} else {
$selected = "";
}
$html .= "<OPTION VALUE=\"$key\" $selected>$labels[$key]\n";
next($labels);
$key = key($labels);
}
$html .= "</SELECT>\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";
?>
<!DOCTYPE HTML PUBLIC "-//AdvaSoft//DTD HTML 3.2 experimental 961018//EN">
<HTML>
<HEAD><TITLE>Title</TITLE></HEAD>
/* 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;
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 . "%'";
<?php
switch($numrows):
case 0:
echo "There were no matches to your search for <FONT COLOR=\"#FF0000\">" . $searchfor;
echo "</FONT> in " . $searchon . ". You may wish to try again with a different search phrase.";
break;
Erwin Penders wrote :7
Hi, great script, but it doesn't work 100% ! Can you add the
mysqlcheck.inc so i can find the fault. (when i search for
the result, and i press the next button i get a MySQL
error.)
Thanks!
David Robley wrote :13
BUG
The line
$query .= "LIKE '%" . $searchfor . "%' LIMIT " . ($offset !=
0 ? "$offset, ": "$NUM_RECS");
This will cause the error ") is not a Mysql index" in second
searches.
Sharaaz Khan wrote :21
I tried the bug fix, but the same error persists. Any idea why? Following is the error:
Warning: 0 is not a MySQL result index in ./../next.php3 on line 145
Helge Schacht wrote :23
This one is fine but-
ist there a way to do this in one query?
--> select * from table where something LIMIT 0,10;
and read the number of affected rows?
This would speed up the query if there is a large
number of records!
Byungjin Chang wrote :48
About the error that Khan Sharaaz`s getting,
it might be the missing space between the query field.
Try adding a space in front of `LIMIT`.
Also, try echoing out the query and see if the query is
correct.
Boaz Yahav wrote :49
Hi
Many times, if you copy/past from a browser window
you get some wierd chars instead of spaces.
I usually paste into notepad (fixed width font editor)
and then copy paste that into my file
Tony Colclough wrote :359
Great useful little tool, just one problem I spent ages
trying to work out...
The hidden field for Search that is passed to the next
page when the next button is clicked passes Search
with a space in front of it, so I had to remove the space
before the PHP code for it to work.
Thanks
Edward Apostol wrote :558
Can anyone tell me where I can find a copy of the include file mysqlcheck.inc that is mentioned in this script? I would like to try it out but I do not have an idea where the file is found.