Where statement - List checkboxes (multi value)

3 posts by 2 authors in: Forums > CMS Builder
Last Post: October 9, 2012   (RSS)

By crazyfish - October 9, 2012 - edited: October 9, 2012

Ok, my brain can't wrap around this problem this morning.
Artist portfolio page results in list form

Field name 'available' in section 'portfolio'

List options available, sold, student, print ( some single checks some multi )
as a checkboxes ( multi value)

I have 3 pages for lists available, sold and prints

I can't seem to get the Where statement correct. IF any record is "available" ( or sold or prints ) show it

list($portfolioRecords, $portfolioMetaData) = getRecords(array(
'tableName' => 'portfolio',
'perPage' => '21',
'where' => "available LIKE '%\tavailable\t%'",
));

Now that only shows "available" where ONLY "available" is checked, but it two fields are checked ie available + print it drags up a different list.

I know this isn't completely clear but hopefully you understand what I need.

What is the Where statement for a list type if any of the multi values match?

Re: [crazyfish] Where statement - List checkboxes (multi value)

Hi,

From what I understand your trying to get any records with at least one box ticked? I've found two ways you could do this in a getRecords function:

'where' => "CHAR_LENGTH(available) > 1"

This will check the length of the string stored in the available field, and if it has at least one charecter it will be returned. So it will return everything with at least on box ticked.

The second way is to do something like this:

'where' => "available LIKE '%available%' OR available LIKE '%prints%' OR available LIKE '%sold%'"

You could also have multiple LIKE statements that return every string that could be stored in the available field, you can add as many of these OR statements as you require.

Let me know if your looking for something different.

Thanks
Greg Thomas







PHP Programmer - interactivetools.com