Help required with search not working.

4 posts by 2 authors in: Forums > CMS Builder
Last Post: June 23, 2017   (RSS)

By willydoit - June 22, 2017

Hi all,

I have a table called advertisers and a field called services_provided.

I have a listing page which displays all the records within the table. I want to place a drop down list containing all the services provided and to be able to select a particular service from the list and then display only the advertisers providing those services.

My page displays all advertisers by default and also displays my drop down list but the search is not filtering the results.  I am sure it will be something simple but for the life of me I cannot see the issue.

My top of page code looks like this;

  // load viewer library
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = array('#############/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."); }

  // load records from 'advertisers'
  list($advertisersRecordsFeatured, $advertisersMetaDataFeatured) = getRecords(array(
    'tableName'   => 'advertisers',
    'orderBy'     => 'RAND()',
    'where'        => 'listing = "Featured Listing"', 

  ));
    list($advertisersRecordsStandard, $advertisersMetaDataStandard) = getRecords(array(
    'tableName'   => 'advertisers',
    'orderBy'     => 'RAND()',
    'where'        => 'listing = "Standard Listing"', 

  ));
    list($advertisersRecordsComplimentary,  $advertisersMetaDataComplimentary) = getRecords(array(
    'tableName'   => 'advertisers',
    'orderBy'     => 'RAND()',
    'where'        => 'listing = "Complimentary Listing"', 

  ));

?>

and my drop down list and search form looks like this

 <form method="post" action="http://www.lpl-testsite.co.uk/bridlington-business-directory.php?">
        
        
       <select name="services_provided">
        <?php foreach (getListOptions('advertisers', 'services_provided') as $value => $label): ?> 

<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['services_provided']);?>>

<?php echo $label; ?></option> 

<?php endforeach ?> 

      
         
         </select>
<br/>
        
        
        <div align="center">
          <input type="submit" name="search" value="  Search Listings  "/>
        </div>
        
        
        
</form>

If anyone can spot the most likely daft mistake I have made I would be grateful for you pointing it out.

Thanks in advance for any help provided.

By Dave - June 22, 2017

Hi willydoit, 

It seems to be working for me.  Which value are you searching for that isn't showing up? 

One tip is in your form tag not to hard code the path.  That way if the hostname, filename, etc changes it will still work and it's easier to copy and paste the form when you want to use it somewhere else.   So you can set your form action="?" and it will use the current PHP page.

Also, when testing the search results code, try just manually entering URLs, eg: 

bridlington-business-directory.php?services_provided=Accountants
bridlington-business-directory.php?services_provided=Bakery

And for the pulldown, I usually try to give a blank first entry like this: 
<option value="">Select a business category</a>

So you're not defaulting to any one category unless that's what you intend to do.

Hope that helps, let me know if you still need help with any part of it.

Dave Edis - Senior Developer
interactivetools.com

By willydoit - June 22, 2017

Hi Dave,

thanks for the help and suggestions, will implement those today, I havent done anything since making the post and it is also working for me now, no idea why. Sorry to have wasted your time.