Multiple Selection List = where Filter

16 posts by 2 authors in: Forums > CMS Builder
Last Post: January 28, 2009   (RSS)

By s2smedia - January 26, 2009

Hi,

I have a news section on my site. When creating a news story you first select the page you want it to appear on.

In the news menu in CMS.. I have a list option that shows the pages that you can display it on... originally I made the list option so you can only select 1 list item.

<?php

require_once "/home/highview/public_html/apexFinal/cmsAdmin/lib/viewer_functions.php";

list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '5',
'where' => " academy = 'Futsal Academy' ",
));

?>

It worked fine...

Now i have changed the list option to allow multiple selections...
but now on the page that is suppose to show the news list, no longer displays them..

do i have to set up the 'where' => " academy = 'Futsal Academy' ", differently since now i have it set up for multiple selections?

Re: [s2smedia] Multiple Selection List = where Filter

By Dave - January 26, 2009

Hi s2smedia,

It's a little more complicated with multi value fields. They're stored as tab separated values in the database so we need to use some mysql wildcard searches to see if the value is _in_ the list as opposed to being an exact match. Try this:

'where' => " academy LIKE '%\tFutsal Academy\t%' ",

LIKE means "matches this pattern", % means "any characters", and \t means tab.

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multiple Selection List = where Filter

By s2smedia - January 26, 2009

That does it!!! Thanks A Million!!!

BTW this site is a MONSTER...power 100% by your great CMS. When its 100% complete I will make sure to post in the forum...

Re: [s2smedia] Multiple Selection List = where Filter

By Dave - January 26, 2009

If it's using the url based searching system where you add: ?fieldname=value then it might work automatically. If not you can add keyword to do a keyword search rather than an exact match:

?fieldname_keyword=value

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multiple Selection List = where Filter

By s2smedia - January 26, 2009

OOpps sorry i thought i posted the code I used:

<?php if ($record['futsal_location'] != $winter_academy_locationsRecord['location']) { continue; } ?>


but now i need it to work with the multiple selection list

Re: [s2smedia] Multiple Selection List = where Filter

By Dave - January 27, 2009

Sure, which one is the multi value field?

Try something like this:

if (strpos($record['futsal_location'], $winter_academy_locationsRecord['location']) !== false) { continue; ?>

If that doesn't work try swapping the variables.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multiple Selection List = where Filter

By s2smedia - January 27, 2009

OK I added that to my code:

<?php foreach ($newsRecords as $record): ?>
<?php if (strpos($record['futsal_location'], $winter_academy_locationsRecord['location']) !== false) { continue; ?>
<?php $bgColor = (@$bgColor == "") ? '#666666' : ''; ?>
<table width="100%" border="0" cellspacing="0" cellpadding="8" >
<tr>
<th align="left" valign="top" bgcolor="<?php echo $bgColor; ?>" scope="col"><span class="newsheadlines2"><?php echo $record['date'] ?></span><br />
<span class="newsheadlines4"> <b><a href="<?php echo $record['_link'] ?>"><?php echo $record['headline'] ?></a></b></span><br />
<span class="newsheadlines2"><?php echo $record['article_snippet'] ?></a></span></th>
</tr>
</table>
<?php endforeach; ?>
<?php if (!$newsRecords): ?>
<span class="newsheadlines2">No records were found!</span><br/>
<?php endif ?>



BUT NOW IM GETTING THIS ERROR:

Parse error: syntax error, unexpected T_ENDFOREACH in /home/highview/public_html/apexFinal/futsallocation_details.php on line 197


Line 197 is somewhere around here:

<?php endforeach; ?>
<?php if (!$newsRecords): ?>
<span class="newsheadlines2">No records were found!</span><br/>
<?php endif ?>

Re: [s2smedia] Multiple Selection List = where Filter

By Dave - January 27, 2009

Looks like I had a typo there. Try adding the trailing curly bracket:

<?php if (strpos($record['futsal_location'], $winter_academy_locationsRecord['location']) !== false) { continue; } ?>

Let me know if that resolves it.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multiple Selection List = where Filter

By s2smedia - January 27, 2009 - edited: January 27, 2009

ah ha!!

That does it

the fields were backwords... but i fixed that..

THANKS 1,000,000!!!