where AND / OR

6 posts by 3 authors in: Forums > CMS Builder
Last Post: April 28, 2011   (RSS)

By Toledoh - April 27, 2011

Hi Guys.

I've got a bunch of "speakers" in a table, that need to be grouped in various ways.

Firstyly, by type... so that's easy;
'where' => 'type="Keynote"',

But then I add a mulit-select as well...

How can I say;
// load records
list($speakersRecords, $speakersMetaData) = getRecords(array(
'tableName' => 'speakers',
'where' => 'type="Keynote"',
'AND WHERE' => 'category LIKE 1'
));

Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] where AND / OR

By zip222 - April 27, 2011

This should do it...

// load records
list($speakersRecords, $speakersMetaData) = getRecords(array(
'tableName' => 'speakers',
'where' => 'type="Keynote" AND category LIKE 1'
));

Re: [zip222] where AND / OR

By Toledoh - April 27, 2011

It doesn't seem to like category LIKE 1'

However I've just used 'where' => 'type="Keynote" AND category = 1' and it works for now as all the speakers have only only 1 category slected.

Any ideas on how to get LIKE to work?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] where AND / OR

By Dave - April 27, 2011

Hi Tim,

Try putting quotes around the LIKE value: LIKE "1"

LIKE supports these "wildcard" characters:
% Matches any number of characters, even zero characters
_ Matches exactly one character

So you can do things like this:
LIKE "%dave%" - matches "dave" anywhere in the string
LIKE "604%" - must start with 604
LIKE "%!" - must end in !
LIKE "1%2" must start with 1 and end in 2

So in CMSB some of the multi-value fields are tab separated. So in MySQL you can represent a tab as \t, so we sometimes search for a value in a tab separated list like this: LIKE "%\tMy Value\t%"

And you can also say: NOT LIKE to return rows that don't match the pattern.

Hope that helps! Let me know if you have any other questions about that.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] where AND / OR

By Toledoh - April 27, 2011

Perfect - thanks Dave!
Cheers,

Tim (toledoh.com.au)