Changing over to finishing the search engine
am 12.03.2011 23:07:44 von Bill MudryFor now, I thank those helping me with the=20
strange absence of some UV photos when others
were showing. The problem still exists, so I will=20
get back to it again on another day when some
matters of greater priority are taken care of.
The highest priority of unfinished programming=20
tasks for my TAXA site is finishing the search
engine. There are 4 organizational levels for the=20
wood data but probably 95% of any queries
or interest in the site will be at the species=20
level, the level that defines all woods and at which
the public can relate. It is only those=20
academically minded who would show interest in the
higher botanical levels. Therefore the search=20
engine I have been working on is being designed
to work only on different columns of one table,=20
the 'species' table. All relevant pages and
query reports are dynamically formed.
Once completed, it will totally make access to=20
the huge amount of data far more user friendly
and versatile and become a key cornerstone for the operation of the website.
I am no ace at PHP, more like slow but=20
determined. This has been the most challenging code
I, personally, have had to work on. I started via=20
a simple, one column, one table search
template from www.designplace.org. Mid stream in=20
my efforts, I designed a way to let users
choose what type of search (what column,=20
actually) they wish to use. Recently I was able to
combine that function into the search form successfully.
All search categories work successfully ---- but=20
at present, only the first page of a query.
Page control is accomplished through two PHP_SELF=20
statements, one to advance to the next
page (until the end of the report is finished)=20
and the other to go back a page. At one point,
I had the forward action working right to the=20
last page of a query. Now neither the page=20
advancement nor the page reversing now works past=20
the first page being reported ---- and I am not=20
sure what I messed up ;-( :-[ . After getting the=20
first page showing, pressing either the previous=20
or next button brings out the following preprogrammed statements of:
Sorry, your search: "Pterocarpus"=20
returned zero results (from a genus search)
Couldn't execute query
However, it does not put out a standard PHP error.
If I can get these forward and reverse page=20
actions to work, I expect that the job will be
complete! In case this helps, the two PHP_SELF=20
statements are on lines 478 and 529.
I will list the code for the whole page. There is=20
copious internal documentation and many
"debug" statements to help follow parameter values.
Because of the uncommented debug statements, you=20
can use the actual search page to
follow values .... at:
http://www.prowebcanada.com/taxa/commonname_search.php
Much thanks for any help you can give,
Bill Mudry
Mississauga, Ontario Canada
==================== =====3D=
==================== =====3D=
===================3D
[CODE]
//session_start(); // start up your PHP session!
//$record_counter=3D @$_GET[$record_counter];
//$record_counter =3D $_SESSION['$record_counter']; // Not used=
now.
ECHO "\$record_counter on line 7 is $record_counter
";
$count =3D $record_counter+1;
//$count =3D $_SESSION['$count'];
ECHO "\$count at the top, line 12 is - $count
";
//$_SESSION['$count'] =3D $count;
?>
http://www.designplace.org/">
Knowledge Base web designer and author">
//parse_str($_SERVER['QUERY_STRING'], $qs);
//$record_counter =3D$qs['record_counter'];
//$record_counter =3D 14; hard coded as a debug statement
//ECHO "\$count on line 99 is - $count
"; //debug statement
ECHO "\$record_counter on line 95 is -=20
$record_counter
"; //debug statement
?>
Multi Column Search
//querystring =3D"";
//$querystring =3D"";
$newsearch =3D 0 ; //Equals 1 only on a new search request
//ECHO "
\$newsearch on line 111 is $newsearch
";$submit=3D"";
//ECHO "\Ssubmit, before the form, on line 113 is - $submit
";
If ($submit) {$record_counter =3D 0;}
?>
$submit =3D $_GET["submit"];
ECHO "\$submit on line 179 is - $submit
";
$newsearch =3D $_GET["newsearch"];
//ECHO "\$newsearch just past the form on line 180 is - $newsearch
";
IF ($newsearch=3D1) {$record_counter=3D0;};
ECHO "\$record_counter on line 185 is - $record_counter
";
/*
==================== =====3D=
==================== =====3D=
==================== =====3D
XXXXXXXXXXX GET THE SEARCH TYPE AND SEARCH STRING FROM THE FORM XXXXXXXXXXX
==================== =====3D=
==================== =====3D=
==================== =====3D
*/
$searchtype =3D $_GET['searchtype'] ;
$searchtype =3D trim($searchtype); //trim=20
whitespace from the stored variable
//ECHO "On line 192, \$searchtype is -=20
$searchtype
"; // Debug statement
$querystring =3D @$_GET['querystring'] ;
$querystring =3D trim($querystring);=20
//trim whitespace from the stored variable
//=20
==================== =====3D=
==================== =====3D=
==================== =====3D=
==========
// REASSURE USER OF THEIR CHOICES. (ALSO GOOD FOR DEBUGGING).
If (!empty($searchtype))
{
ECHO " align=3D'center'>searching under $searchtype for:=20
"" . $querystring . """;
}
//ECHO "Line 204 - \$searchtype=20
is - $searchtype
"; //debug statement
/*
==================== =====3D=
==================== =====3D=
==================== =====3D=
====
XXXXXXXXXXXXXXXXX TRANSLATION OF SEARCH TYPE TO=20
COLUMN NAME XXXXXXXXXXXXXXXXX
==================== =====3D=
==================== =====3D=
==================== =====3D=
====
*/
$searchfield =3D "";
//ECHO "Line 196 - \$searchtype is -=20
$searchtype
"; // Debug statement
switch ($searchtype) {
case "common names":
$searchfield =3D trim("species_commonname");
//ECHO "
common names - $searchfield
\n";
break;
case "botanical names":
$searchfield =3D trim("species_name");
//ECHO "
botanical=20
names - $searchfield
\n";
break;
case "genus":
$searchfield =3D trim("genus_name");
//ECHO "
genus -=20
$searchfield
\n";
break;
case "location":
$searchfield =3D trim("location");
//ECHO "
location -=20
$searchfield
\n";
break;
case "description":
$searchfield =3D trim("species_description");
//ECHO "
description=20
- $searchfield
\n";
break;
default: If (!isset($searchfield)) {
ECHO "Please choose a search type first";
}
}
/*
==================== =====3D=
==================== =====3D=
==================== =====3D=
====
XXXXXXXXXXXXX END OF TRANSLATION OF SEARCH TYPE TO COLUMN NAME =
XXXXXXXXXXXXXX
==================== =====3D=
==================== =====3D=
==================== =====3D=
====
*/
// Get the search variable from URL. Old=20
designations were $var =3D @$_GET['q'] ;
$newquerystring =3D @$_GET['querystring'] ;
$querystring =3D trim($newquerystring); //trim=20
whitespace from the stored variable
$count =3D $record_counter +1;
$newsearch =3D @$_GET['newsearch'] ;
ECHO "\$newsearch on line 255 is $newsearch";
if ($newsearch > 0) {$record_counter=3D0;};
=
/*===================3D= 3D=====
==================== =====3D=
====================
XXXXXXXXXXXXX SET THE NUMBER OF RECORDS PER PAGE HERE =
XXXXXXXXXXXXXX
=
==================== =====3D=
==================== =====3D=
===================3D*/
$limit=3D'30';
// check for an empty string and display a message.
if ($querystring == "")
{
ECHO "
Please enter a search string...
";exit;
}
// check for a search parameter
if (!isset($newquerystring))
{
ECHO "
We dont seem to have a search parameter!
";exit;
}
/*===================3D= 3D=====
==================== =====3D=
==================== =====3D=
===============3D
XXXXXXXXXXXXXXXXXXXXXXXXXXX Connect to the=20
TAXA Database XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
=
==================== =====3D=
==================== =====3D=
==================== =====3D=
==============*/
include ("connecttotaxa.php");
$connection =3D mysql_connect($hostname, $username, $password)
or die("Unable to connect to database server");
//specify database ** EDIT REQUIRED HERE **
mysql_select_db("taxa") or die("Unable to select=20
the TAXA database"); //select which database we're using
/*===================3D= 3D=====
==================== =====3D=
========
XXXXXXXXXXXXXXX BUILD THE SQL QUERY XXXXXXXXXXXXXXXXXXXX
==================== =====3D=
==================== =====3D=
=======3D*/
// Build SQL Query
$searchquery =3D "SELECT *
FROM species
WHERE $searchfield like \"%$querystring%\"
order by '$searchfield'";
$numresults=3Dmysql_query($searchquery);
@$numrows=3Dmysql_num_rows($numresults);
/*===================3D= 3D=====
==================== =====3D=
==================== =====3D=
==================== =3D
XXXXXXXXXXXXXXX TEST FOR ZERO RESULTS AND=20
PRINT A MESSAGE OF THAT IF TRUE XXXXXXXXXXXXXXXXXXXX
==================== =====3D=
==================== =====3D=
==================== =====3D=
==================== =3D*/
if ($numrows == 0)
{
ECHO "
Search Results
";ECHO "
Sorry, your search:=20
"" . $querystring. "" returned zero results
}
/*===================3D= 3D=====
==================== =====3D=
========
// $record_counter is the record counter for the present record
// next determine if s has been passed to script, if not use 0
==================== =====3D=
==================== =====3D=
=======3D*/
if (empty($s)) {
$record_counter=3D0;
}
/*===================3D= 3D=====
==================== =====3D=
==================== =====3D=
=3D
XXXXXXXXXXXXXXX QUERY THE DATABASE TO GET THE RESULTS =
XXXXXXXXXXXXXXXXXXXX
==================== =====3D=
==================== =====3D=
==================== =====3D*=
/
// get results
$searchquery .=3D " limit $record_counter,$limit";
$result =3D mysql_query($searchquery) or die("Couldn't execute query");
/*===================3D= 3D=====
==================== =====3D=
==================== =====3D=
===============3D
XXXXXXXXXXXXXXX ECHO BACK TO THE USER WHAT=20
THEY ASKED TO SEARCH FOR XXXXXXXXXXXXXXXXXXXX
==================== =====3D=
==================== =====3D=
==================== =====3D=
==============*/
ECHO "
You searched for: ""=20
.. $querystring . ""
//////////////////////////////////////////////////////////// /////
// ********** REPORTING STARTS HERE ********** //
//////////////////////////////////////////////////////////// /////
/*===================3D= 3D=====
==================== =====3D=
===============3D
XXXXXXXXXXXXXXX SET A TITLE FOR THE REPORT XXXXXXXXXXXXXXXXXXXX
==================== =====3D=
==================== =====3D=
==============*/
ECHO "
Search Results -=20
$numrows references found.
";// now you can display the results returned
/*===================3D= 3D=====
==================== =====3D=
==================== =====3D
XXXXXXXXXXXXXXX SET UP COLUMN HEADERS FOR THE REPORT =
XXXXXXXXXXXXXXXXXXXX
==================== =====3D=
==================== =====3D=
==================== ====*/
ECHO "
ECHO "
ECHO "
//ECHO "Common Name";
ECHO "Common Name";
ECHO "
ECHO "
ECHO "Botanical Name";
ECHO "
ECHO "
ECHO "Authorities";
ECHO "
ECHO "
ECHO "Genus Name";
ECHO "
ECHO "
ECHO "Location";ECHO "
ECHO "
ECHO "Comments";
ECHO "
if (!isset($count)){$count=3D1;};
ECHO "
ECHO "
/*===================3D= 3D=====
==================== =====3D=
=======3D
XXXXXXXXX PRINT OUT RECORDS TILL END OF QUERY XXXXXXXXX
************** WHILE LOOP STARTS HERE ******************
==================== =====3D=
==================== =====3D=
======*/
while ($row=3D mysql_fetch_array($result)) {
$commonname =3D $row["species_commonname"];
$botname =3D $row["species_name"];
$authorities =3D $row["authorities_species"];
$genusname =3D $row["genus_name"];
$location =3D $row["location"];
$comments =3D $row["comments"];
ECHO "
//ECHO "\$count is $count
";
ECHO "$count $commonname
" ;
ECHO "
ECHO "
ECHO "";
ECHO "$botname
";
ECHO "
\n";
ECHO "
ECHO "
ECHO "$authorities
";
ECHO "
ECHO "
ECHO "$genusname
";
ECHO "
ECHO "
ECHO "$location
";
ECHO "
ECHO "
ECHO "$comments
";
ECHO "
ECHO "
ECHO "
$count++ ;
$record_counter++ ; // DOESN'T $record_counter=20
HAVE TO BE INCREMEENTED FOR EACH ROW PRINTED ALSO??
// ANOTHER COPY WORKED A FEW MONTHS AGO=20
WITHOUT IT. iT IS NOT IN THE TEMPLATE.
//ECHO "\$record_counter on line 412 is -=20
$record_counter
"; //debug statement
}
/*===================3D= 3D=====
==================== =====3D=
=======3D
XXXXXXXXX END OF WHILE LOOP. XXXXXXXXX
==================== =====3D=
==================== =====3D=
======*/
////////////////////////////////////////////////////////////
// CLOSE THE REPORT TABLE
////////////////////////////////////////////////////////////
ECHO "
ECHO "";
ECHO "
";
ECHO "\$record_counter on line 436 at the end of=20
the report loop is - $record_counter
";
// Calculate the current page
$currPage =3D (($record_counter/$limit) + 1);
$pages =3D $currPage; //
ECHO "\$currPage on line 451 is - $currPage
"; //debug statement
ECHO "\$record_counter on line 452 is -=20
$record_counter
"; //debug statement
//break before paging
ECHO "
";
// next we need to do the links to other results
//////////////////////////////////////////////////////////// //////////
// If $record_counter is less than 1, there are=20
no more records to view backwards.
//////////////////////////////////////////////////////////// //////////
// bypass PREV link if s is 0 since there must be=20
at least one more record to display to use a new page.
if ($record_counter>=3D1) {
ECHO "\$record_counter at line 453 is -=20
$record_counter
"; //debug statement
$prevs=3D($record_counter-$limit);
ECHO "\$prevs at line 455 is - $prevs
"; //debug statement
//////////////////////////////////////////////////////////// ////////////////=
//////////////////
// ****** This statement will run the prior=20
page of the report. It is user chosen******
//
//////////////////////////////////////////////////////////// ////////////////=
//////////////////
print " href=3D\"$PHP_SELF?record_counter=3D$prevs&querystring=3D$qu erystring&search=
field=3D$searchfield\">
<<=20
Previous $limit records
} //END OF PRESENT IF STATEMENT
// calculate number of pages needing links
$pages=3Dintval($numrows/$limit);
//ECHO "\$pages on line 469 is - $pages
"; //debug statement
//ECHO "\$numrows on line 470 is - $numrows
"; //debug statement
//ECHO "\$limit on line 471 is - $limit
"; //debug statement
// $pages now contains int of pages needed unless=20
there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
//ECHO "\$pages on line 479 is - $pages
"; //debug statement
$remainder =3D ($numrows%$limit);
//ECHO "\$remainder on line 353 is - $remainder
"; //debug statement
ECHO "
";
//$x =3D ($record_counter+$limit)/$limit
//ECHO "\$x on line 478 is - $x
"; //debug statement
ECHO "\$record_counter on line 479 is -=20
$record_counter
"; //debug statement
//ECHO "\$limit on line 490 is - $limit
"; //debug statement
//ECHO "\$pages on line 491 is - $pages
"; //debug statement
// check to see if last page
if (!((($record_counter+$limit)/$limit)==$pages) && $pages!=3D1) {
ECHO "
";
// not last page so give NEXT link
$news=3D$record_counter+$limit;
ECHO "\$record_counter on line 517 is -=20
$record_counter
"; //debug statement
//ECHO "\$limit on line 492 is - $limit
"; //debug statement
//ECHO "\$news on line 493 is - $news
"; //debug statement
//ECHO "
////////////////////////////////////////////////////////////
// This statement will run the next page of the report.
// It is user chosen
////////////////////////////////////////////////////////////
//echo " Next 10=
>>";
ECHO " href=3D\"$PHP_SELF?record_counter=3D$news&querystring=3D$new querystring&sear=
chfield=3D$searchfield\">
Next=20
$limit records >>
ECHO "
}
ECHO "\$record_counter on line 534 is -=20
$record_counter
"; //debug statement
$record_counter =3D $news;
ECHO "\$record_counter on line 538 is -=20
$record_counter
"; //debug statement
//$_SESSION['$record_counter'] =3D $record_counter;
//$_SESSION['$count'] =3D $count;
?>
[/CODE]
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php