"No matching results found" message

8 posts by 3 authors in: Forums > CMS Builder
Last Post: May 8, 2013   (RSS)

I'm sure there must be an easy solution to this, but it's Friday afternoon!

I have a search page and results page, both of which are working fine. However, if there are no matching results, the page is basically blank; e.g. http://www.colourparadise.com/plants-results.php. I'd like to have a message on this page of no matches are found, but where should I put it in the code?

Thanks.

By rconring - May 3, 2013

Here is an example.  You will have to replace the appropriate variables with your table record.

In the header, my table viewer:

  list($includesRecords, $includesMetaData) = getRecords(array(
    'tableName'   => 'includes',
    'where'    => "category = '$num'", // Category passed in URL
    'loadUploads' => false,
    'allowSearch' => false,
  ));

and down in the results display area:

    <!-- If records exist -->
    <?php if($includesRecords): ?> 
      <?php foreach ($includesRecords as $record): ?>        
          <!-- DO YOUR DISPLAY STUFF -->
      <?php endforeach ?>  
    <!-- otherwise -->
    <?php else: ?> 
        <?php echo "Sorry, no search results" ?>
    <?php endif ?>

Just replace $includesRecords with your table record array name.

That should do it.

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Thanks for your suggestion, Ron. I added the following to the head of my search results page:

  list($categoriesRecords, $categoriesMetaData) = getRecords(array(
    'tableName'   => 'categories',
    'loadUploads' => false,
    'allowSearch' => false,
  ));

and this to the display area:

    <!-- If records exist -->
    <?php if($categoriesRecords): ?>
      <?php foreach ($categoriesRecords as $record): ?>        
          <!-- DO YOUR DISPLAY STUFF -->
      <?php endforeach ?>  
    <!-- otherwise -->
    <?php else: ?>
        <?php echo "Sorry, no search results" ?>
    <?php endif ?>

However, there's still nothing showing up when I search for a keyword I know doesn't exist.

When I include the code     'where'    => "category = '$num'", // Category passed in URL

I got an error message - Notice: Undefined variable: num in /home/colourp1/public_html/plants-results.php on line 14 MySQL Error: Unknown column 'categories' in 'where clause' - and nothing showed up at all.

http://www.colourparadise.com/plants.php

http://www.colourparadise.com/plants-results.php

By Steve99 - May 7, 2013

Hi,

A couple of things to help out to get you going in the right direction:

If you are looking to use the basic built in search features CMSB has, here is a good starting point discussed in a previous thread:
http://www.interactivetools.com/forum/forum-posts.php?postNum=2218266#post2218266

For basic searches you would disregard the "where" clause. You would list out all of the fields in the hidden form field element followed by your criteria. For advanced searches you would construct your string as the "where" clause. 

It doesn't sound like the previous post will suit your needs, however it would work well as a detail page.

As far as just explaining the errors you received, the notice means that the variable $num doesn't exist. Either that variable doesn't exist at and isn't used at all or it isn't being set. If it isn't being set, then just add @ to it so it's @$num.

The MySQL error is telling you that you are trying to query a field that doesn't exist. Either it truly doesn't exist or your "where" clause has issues. This example would be for searching a single field for a passed value:

    'where' => 'the_field_name = "'.$the_variable_name.'"', 

If you are looking to query multiple fields, then you would construct your search string for the "where" clause.

A useful feature of CMSB is the built in debug SQL. It will print out your query:

    'debugSql' => true, 

Hope this helps.

Steve

By Steve99 - May 7, 2013

Hi again,

I jumped on this thread late in the game and picked up where it left off. I just read your first post...

You already have the code in your file:

<?php if (!$product_detailsRecords): ?>Put your message here<?php endif; ?> 

That will display the message where the search results would have been.

If you want to change up your "Search Results for search term" so if for some reason there ends up being no search term entered, you can do something like this:

<?php if (!$product_detailsRecords): ?>
Message for if nothing is entered / variable empty
<?php else: ?>
Search Results for <?php echo @$_REQUEST['theVariable']; ?>
<?php endif; ?> 

Hope this helps.

- Steve

By CommonSenseDesign - May 8, 2013 - edited: May 8, 2013

Thanks, Steve. Your second solution works perfectly. http://www.colourparadise.com/plants.php

And thank you to everyone else who offered suggestions, too. I appreciate your time and help.

By Steve99 - May 8, 2013

You're very welcome!

- Steve