Product list by tick box

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 1, 2014   (RSS)

Hi Crystal, 

When you have a single list item, CMS Builder stores the value without any formatting, for example "1" or "supermarket". But if you have a multi checkbox list, it stores the values in a tab separated list for example "    supermarket     " or "    supermarket     house    ". So instead of using equal to, you should search for the value instead:

  <?php foreach ($testRecords as $record): ?>
  <?php if (strpos($record['retail'],"\tsupermarket\t") === false){ continue; ?>
 
      Record Number: <?php echo htmlencode($record['num']) ?><br/>
      Title: <?php echo htmlencode($record['title']) ?><br/>
      Content: <?php echo $record['content']; ?><br/>
      

So the strpos (http://ca2.php.net/strpos) function is used to search a string for the contents of another string. In this case we're searching the $record['retail'] field to see if it contains supermarket, if it doesn't then the item is skipped.

The \t values ensure that supermarket starts and ends with tab spaces, to ensure we only return the value supemarket and not supermarketer, or another value that contains supermarket.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By crystal - February 1, 2014

Hi Greg

Thanks for the reply and lesson

I managed to get around it by the following:- 

// load records from 'test'
list($testRecords, $testMetaData) = getRecords(array(
'tableName' => 'test',
'where' => "retail LIKE '%\tsupermarket\t%' ",
'loadUploads' => true,
'allowSearch' => false,
));

(found this on your forum - many thanks)

Chris

CT