"No matching results found" message

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

By CommonSenseDesign - May 3, 2013

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

By rconring - May 7, 2013

Oh wow ... sorry, I sent you an example viewer code that does not pertain to what you are doing.  The $num variable is set with getNumberFromEndOfUrl() function and is used in several places on my page but does not apply to yours.  

Secondly, the viewer has allow search set to false.  Just ignore the viewer code.  All you are wanting is the logic to display "no records" if the viewer finds no product records matching the search criteria passed in the page.  Should you not be searching the product data rather than the category data?  Without seeing your data schema I cannot be any more specific than that.

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

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