I need a little assistance on a list viewer query if possible

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 27, 2015   (RSS)

By kkegans - April 27, 2015

I am not a PHP/MYSQL coder, and need a bit of help if possible?

How can I construct a load records query that will return all records if there are no variables passed in the URL, but only the records matching the passed variable if on exists?

Here is what I have now, and it works great if the variable is passed, but I also would like the default URL to return all of the list records?

  // load records from 'products_list'
  list($products_listRecords, $products_listMetaData) = getRecords(array(
    'tableName'   => 'products_list',
    'loadUploads' => true,
    'allowSearch' => true,
    'where' => "category = '$_GET[category]'",

Thanks for your help!

CMSB Rocks!



By Dave - April 27, 2015

Hi Kurt, 

You don't need to do this, CMSB does it automatically (also you're passing in user-input without escaping it so there's a security risk there):

'where' => "category = '$_GET[category]'",

Try just removing that line and still passing ?category=[your value] in the url.  It should work exactly the same not not filter on that when category isn't defined.  

That's what "allowSearch" does (and it's enabled by default unless you set it to false).

Here's some more info on that: http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

Give that a try and let me know any questions or problems.


Dave Edis - Senior Developer

By kkegans - April 27, 2015

Dave,  Thanks!!!

Leave it to me to try to make it difficult  ;-)

CMSB Rocks!