Couple of Questions on CMS builder

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

Re: [greatjakes] Couple of Questions on CMS builder

By Dave - January 22, 2009

Hi greatjakes, welcome to the CMS Builder forum! :)

For your first question, yes that's possible. When you have a list viewer you can add a line of code to "filter" the results. So for 2 and 3 that might look like this:

>2. On Principal page, show list of principals only
'where' => ' principal = 1 ',
This assumes you had a checkbox called "principal

>3. On individual practice areas page, we want to
>display only the ones associated with that practice >areas.
'where' => ' practice_area = "corporate" ',
This assumes you had a single value pulldown called "practice_area" with a option for "corporate". You could also do this with multiple checkboxes for practice areas.

And on your second question. There's no easy way to do this without some custom php code. We don't typically include that but here's some that will do that:

<?php
$namesArray = array($record['author1_name'], $record['author2_name'], $record['author3_name']);
$namesArray = array_filter($namesArray); // remove blank names
$names = join(", ", $namesArray); // join names with commas
$names = preg_replace("/(.*),/", '\\1 and', $names); // replace last comma with "and"
?>

<?php echo $names ?>


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

Re: [Dave] Couple of Questions on CMS builder

[font "Calibri"]Thanks Dave for getting back to me.

[font "Calibri"]For question 1, list works when I set the list as single pull down option, but doesn’t work when I have the list as multi value checkboxes or multi value pull down. When I view the page, I get “No records were found!” I have practice_area field set as list with multi value checkboxes because some attorneys are associated with multiple practice areas.
[font "Calibri"]Below is the code I have on the page:

[font "Calibri"]list($listRecords, $listMetaData) = getRecords(array(
[font "Calibri"]'tableName' => 'list',
[font "Calibri"]'where' => 'practice_area = "corporate"',
[font "Calibri"]));


[font "Calibri"]For question 2, the code you provided does exactly what I want. Thank you very much. [font "Calibri"]However, now I want to separate “name1” into two fields, so it becomes “name1_firstname” and “name1_lastname”. Then add commas and “and” between each fullname, so it displays: "fullname 1, fullname2 and fullname3".

Here is my code :
[font "Calibri"]<?php echo $record['author_1_first_name'] ?> <?php echo $record['author_1_last_name'] ?>
[font "Calibri"]<?php echo $record['author_2_first_name'] ?> <?php echo $record['author_2_last_name'] ?>
[font "Calibri"]<?php echo $record['author_3_first_name'] ?> <?php echo $record['author_3_last_name'] ?>

[font "Calibri"]This isn't a CMS question but I would really appreciate it if you can help me with this. Thanks in advance!

Re: [greatjakes] Couple of Questions on CMS builder

By Dave - January 22, 2009

Hi greatJakes,

Multi Value fields are stores as tab separated values, so the SQL is a little different. Try this:

'where' => 'practice_area LIKE "%\tcorporate\t%"',

Which means "matches "corporate" surrounded by tabs with any other characters on either side. Note that usually we don't need to get this complicated this fast! :)

For question 2, try this:

<?php

$namesArray = array(
$record['author_1_first_name'] .' '. $record['author_1_last_name'],
$record['author_2_first_name'] .' '. $record['author_2_last_name'],
$record['author_3_first_name'] .' '. $record['author_3_last_name']
);

$namesArray = array_filter($namesArray); // remove blank names
$names = join(", ", $namesArray); // join names with commas
$names = preg_replace("/(.*),/", '\\1 and', $names); // replace last comma with "and"
?>


The . combines two bits of text together. First name, then space, then lastname.

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

Re: [Dave] Couple of Questions on CMS builder

Great! list is working now. thank you very much.

However, I’m still having difficulty in getting question 2 to work. Code works with three names. But if there are less than three, it displays like this:
If there is one full name -> John Doe1, and
If there are two names -> John Doe, John Doe2, and

Here is what it should look like:
for one name: John Doe1
for two names: John Doe 1 and John Doe2
for three names: John Doe, Jane Smith and John Doe 3

Here is my code:
<?php
$namesArray = array(
$record['author_1_first_name'] .' '. $record['author_1_last_name'],
$record['author_2_first_name'] .' '. $record['author_2_last_name'],
$record['author_3_first_name'] .' '. $record['author_3_last_name']
);

$namesArray = array_filter($namesArray);
$names = join(", ", $namesArray);
$names = preg_replace("/(.*),/", '\\1 and', $names);
?>
<?php echo $names ?>

Thanks!

Re: [greatjakes] Couple of Questions on CMS builder

By Dave - January 23, 2009

Try this (changes in red)

<?php
$namesArray = array(
join(' ', array_filter(array($record['author_1_first_name'], $record['author_1_last_name']))),
join(' ', array_filter(array($record['author_2_first_name'], $record['author_2_last_name']))),
join(' ', array_filter(array($record['author_3_first_name'], $record['author_3_last_name']))),

);

$namesArray = array_filter($namesArray); // remove blank names
$names = join(", ", $namesArray); // join names with commas
$names = preg_replace("/(.*),/", '\\1 and', $names); // replace last comma with "and"
?>


Sometimes simple things are more complicated then they seem! :)

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