Displaying records by category

2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 9, 2013   (RSS)

By Dave - February 9, 2013

Hi Rui, 

Try this: 

 // load records from 'news'
  list($newsRecords, $newsMetaData) = getRecords(array(
    'tableName'   => 'news',
    'loadUploads' => true,
    'allowSearch' => false,
    'where'       => " category LIKE '%sport%' ",
  ));

If you have multi value fields, you may a few values selected and stored in the field like this "sport european" so a simple " category = 'sport' " test will fail.

In MySQL LIKE is the same as equals but it lets you use wildcards % which mean (Matches any number of characters, even zero characters) so LIKE "%sport%" means "Match anything that has the word "sport" in it, even if there is other content before or after it.

Hope that helps, Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com