Where clause from multi value fields

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

By mbareara - August 3, 2012

Hi and thanks in advance for your help

I have Two tables called "Stagioni" and "Giocatori"

these are the fields

Stagioni
Num
Title

Giocatori
Num
Cognome
stagione (it is a multi value fields...related to stagioni.num)

In each Stagioni detail page i would put the related Giocatori Items

This is my code

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/calciocatania/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($stagioniRecords, $stagioniMetaData) = getRecords(array(
'tableName' => 'stagioni',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$stagioniRecord = @$stagioniRecords[0]; // get first record

// load records
list($giocatoriRecords, $giocatoriMetaData) = getRecords(array(
'tableName' => 'giocatori',
'where' => 'giocatori.stagione = ' . getNumberFromEndOfUrl(),
'orderBy' => 'cognome ASC',
'leftJoin' => array(
// foreign table => local field (that matches num in foreign table)
'stagioni' => 'stagione',
),
));

?>


But it doesn't work because the where clause search only the first value of giocatori.stagioni, while i would select one of multi values of the field

Thank you and sorry for my awful english

Re: [orazio] Where clause from multi value fields

By mbareara - August 3, 2012

ok solved :D

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/calciocatania/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($stagioniRecords, $stagioniMetaData) = getRecords(array(
'tableName' => 'stagioni',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$stagioniRecord = @$stagioniRecords[0]; // get first record

// load records
list($giocatoriRecords, $giocatoriMetaData) = getRecords(array(
'tableName' => 'giocatori',
'where' => "stagione LIKE '%\t".intval($stagioniRecord['num'])."\t%'",
'orderBy' => 'cognome ASC',

));

?>