Search results page

11 posts by 2 authors in: Forums > CMS Builder
Last Post: October 16, 2013   (RSS)

By Rewmer - October 12, 2013

I'm trying to setup a simple search on one of my pages. I have the form code ok which sends through to results page, but I'm not sure of the code needed to show the results. Do I use the record loading code from the search page on my results page ? And can anyone give me the basics code to show the results that I can build on ?

thanks

andy

Hi Andy,

Here's a recipe from my CMSB Cookbook http://www.thecmsbcookbook.com that might answer some of your questions.

If this type (or any other type) of basic search form is put on your list page, only the records that match the search criteria will be displayed.

the $_SERVER['PHP_SELF'] displays the search results on the same page as the form, so you might only need the list page.

There are a number of other recipes in the cookbook that take the concept to a more complex level.

Hope it helps a bit.

Jerry Kornbluth

__________________________________________________________________________________________

SETTING UP BASIC SEARCHES

Here’s some basic code that you can use to set up a simple search box on the list page of a multi-record editor to return only those
records that match your search criteria.

_____ code ________________________________________________

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="text" name="your_field_name_your-criteria" value="">
<input type="submit" name="submit" value="Search">
</form>

Notice the “name” entry on the sample form above. It starts with the field in which you want to preform the search (your_field_name) and
is followed by a modifier that determines what type of search is to be performed (_your-criteria).

CMSB is set up to allow you to search by many criteria by changing ( _your-criteria) in the “name” entry to one of these:

_match - an exact match
_keyword - will look for specific words
_prefix - starts with keyword (or letter)
_query - allows google-style query searches such as: +dog -cat "multi word phrase". Only records matching EVERY word or quoted phrase are
returned. Words or phrases that start with - mean "must not match". The + is optional and not required.
_fieldname_empty Matches blank fields Matches fields that are blank (""). Example: email_empty=1
_min - A minimum value for numeric searches
_max - A maximum value for numeric searches
_year year number for date searches
_month - month number for date searches
_day - Day of month for date searches

So, let’s say you’ve set up a field called “fruit” that can contain one or more keywords, like Apple, Banana, Pear, Orange.

Here’s the basic code that you would use to search for one of those.

_____ code ________________________________________________

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="text" name="fruit_keyword" value="">
<input type="submit" name="submit" value="Search">
</form>

__________________________________________________________

If the visitor entered Apple, Banana, Pear, or Orange, only those records that contained the keyword would be listed.

You could also change the form to include a drop down menu of choices instead of the text box like this:

_____ code ________________________________________________

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">

<select name="fruit_keyword">
<option value="">Please Choose a Fruit</option>
<option value="Apple">Apple</option>
<option value="Banana">Banana</option>
<option value="Pear">Pear</option>
<option value="Orange">Orange</option>
</select>

<input type="submit" name="submit" value="Search">
</form>

__________________________________________________________

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Rewmer - October 15, 2013 - edited: October 15, 2013

Hi Jerry,

 Had a chance to have a play. have my search box on the page and  it looks OK, but searching for anything is not bringing up any results.

I checked my DB and there is defiantly a field called "breeding" that I want to search that has all the different breeding in it.

The page is here http://www.genetic-gems.com/pages/royalavailable2.php

I tried removing all the code that displays the results, but still nothing ????

This is the code I have used as per your example

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
 <input type="text" name="breeding"_keyword value="">
 <input type="submit" name="submit" value="Search">
 </form>

I am a little stumped at the moment - any suggestions ?

Andy

Andy,

Try changing this:

<input type="text" name="breeding"_keyword value="">

to this: (Quote after _keyword)

input type="text" name="breeding_keyword" value="">

See if that helps.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Rewmer - October 15, 2013

No change there Jerry.

I can see its doing something as the wait symbol appears on the page tab - but no results..

Strange.

Andy

I've got to run out, but I'd suggest mocking up a simple page with a simple search form and make sure that you can get it to work first. Then go from there.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Rewmer - October 15, 2013 - edited: October 15, 2013

Ok Ive tried making a simple page as below

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

 <?php    $libraryPath = 'cms/lib/viewer_functions.php';
  $dirsToCheck = array('/home/genetic/public_html/','','../','../../','../../../');

  foreach ($dirsToCheck as $dir) { if (@include_once("../$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }  
  list($avaliable_royal_pythonsRecords, $avaliable_royal_pythonsMetaData) = getRecords(array(     'tableName'   => 'avaliable_royal_pythons',  
   'loadUploads' => true,     'allowSearch' => false,  'perPage'     => '5',   )); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title> </head> <form method="POST" action="<?php echo $_SERVER['../PHP_SELF'] ?>">
 <input type="text" name="breeding_keyword" value="">  
<input type="submit" name="submit" value="Search">
 </form> <body> </body> </html>

But get the error "notice: Undefined index: ../PHP_SELF in /home/genetic/public_html/pages/search.php on line 22"

Line 22 refers to

 <form method="POST" action="<?php echo $_SERVER['../PHP_SELF'] ?>">

 I know im missing something simple. --------------------- I think Ive just seen it------------------

Andy

Try this 

<?php echo $_SERVER['PHP_SELF'] ?>

in place of this

<?php echo $_SERVER['../PHP_SELF'] ?>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Rewmer - October 16, 2013

Hi Jerry, thanks.

Yep that helped. Im now have a working test page, but putting the code into the full page still does not work. I guess some of my code is upsetting things

I will have a trawl through editing out lines until I find the culprit.