Issue with multi records from another table

4 posts by 2 authors in: Forums > CMS Builder
Last Post: April 5, 2010   (RSS)

By theclicklab - March 31, 2010 - edited: March 31, 2010

Hi there, Having issues displaying some data, nothing is showing (blank)

I have a field setup like this:

List (multi value)
Get options from database
Section Table Name: yachts
Use this field for option values: num
Use this field for option labels: yacht_name

In the template I have this to grab the multiple records:

<?php
// Gets list of yachts
$num2 = $nl_multiRecord['yachts'];
if (!$num2) { $num2 = 1; } // default num
list($yachtsRecords, $yachtsMetaData) = getRecords(array(
'tableName' => 'yachts',
'where' => "num LIKE '$num2'", //Gets multiple records
'allowSearch' => '0',
));
?>


And this to print out details:

<?php foreach ($yachtsRecords as $record): ?>
Yacht Name: <?php echo $record['yacht_name'] ?><br/>
<?php endforeach ?>


Any idea why I'm not getting any output? See attached.

Many Thanks!
Attachments:

multi.php 9K

Re: [aquaman] Issue with multi records from another table

By Chris - April 1, 2010

Hi aquaman,

A "multi value" list field will contain, for example:

tab 1 tab 2 tab 3 tab

... which is represented in both PHP and MySQL as:

"\t1\t2\t3\t"

So, to get the records listed there, you'd need to change that to a comma-separated list, then use MySQL's "IN" operator:

$numsTabbedList = $nl_multiRecord['yachts'];
$numsTabbedList = trim($numsTabbedList);
$numsCommaList = str_replace("\t", ",", $numsTabbedList);

if ($numsCommaList) {
list($yachtsRecords,) = getRecords(array(
'tableName' => 'yachts',
'where' => "num IN ($numsCommaList)",
'allowSearch' => '0',
));
}
else {
$yachtsRecords = array(); // empty array
}


I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [aquaman] Issue with multi records from another table

By Chris - April 5, 2010

Hi aquaman,

Glad I could help! :)
All the best,
Chris