EXCLUDING A VALUE From a Checklist

6 posts by 2 authors in: Forums > CMS Builder
Last Post: January 26, 2018   (RSS)

Hello! 

Can someone please tell me how to exclude a value from a checklist?  I'll explain: 

I have a list of Stallions.  Each stallion has a checkbox list so mark all things relevant to that stallion.  ( ie:  New, Hunter, Jumper, Dressage, Pony, Archived )

I've been using this code for the listing to just list one value from the checklist (ie: Archived ) - which creates a list of all Archived Stallions on a single page. 

<?php $count = 0; ?>
<?php foreach ($stallion_listRecords as $record): ?>
<?php if (strpos($record['status'],"\tArchived\t") !== false) : ?>

How would I go about doing this same thing but in reverse? I'd like a page that included all other values that have been checked but NOT any with the value of Archived.  There are about 15 checkboxes and they can change so that's why I wanted to to an exclusion of "Archived" rather than just list all of the values I want to include. 

Any thoughts? Thank you! Tina

By leo - January 26, 2018

Hi Tina,

If you don't need a full list of records for the page, I would recommend adding where statements when you get records from the database. In the beginning of your php script there should be something like this:

list($stallion_listRecords, $stallion_listMetaData) = getRecords(
  'tableName' => ...,
  ...
);

Add the where statement like this:

list($stallion_listRecords, $stallion_listMetaData) = getRecords(
  'tableName' => ...,
  'where' => 'status NOT LIKE "%Archived%"',
  ...
);

That should give you all the records that don't have an Archived status. Or you can just replace the exclamation mark with an equal sign like this:

if (strpos($record['status'],"\tArchived\t") === false)

Let me know if you have any questions!

Thanks,

Leo - PHP Programmer (in training)
interactivetools.com

The WHERE statement worked perfectly. Thank you Leo!! 

By leo - January 26, 2018

Sure! You can use:

'status LIKE "%Archived%"'

Note that the "%Archived%" is a wildcard selection pattern. Which means strings like "abc123Archived" or "Archivedabc123" will also match the pattern. Normally it won't be a problem but in case if it creates confusion you may want to change it to "%\tArchived\t%".

For more information about mysql string comparison you can find them here: https://dev.mysql.com/doc/refman/5.7/en/string-comparison-functions.html

Thanks!

Leo - PHP Programmer (in training)
interactivetools.com

awesome! Thanks so much!!