Where value in Pillbox list

2 posts by 1 authors in: Forums > CMS Builder
Last Post: February 15, 2018   (RSS)

By Ryan - February 14, 2018

Hi All,

Having complete brain freeze on this one. I'm trying to add a where statement to display all articles that contain a match within a list of values stored in a list field. These tables are linked.

Query 1
Returns me the Townland record. In this case the value returned is (1)

Query 2
Searches the articles table for articles that match the selected townland.

The townlands field will contain a comma separated list of values something like (1,3,4,10,11,12) as articles can be related to more than one townland. The issue I'm having is that my query will return values similar to 1 like 10,11 & 12 as well.

Any ideas on how to fix this?

<?php 
   // load record from 'townlands'
  list($townlandsRecords, $townlandsMetaData) = getRecords(array(
    'tableName'   => 'townlands',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $townlandsRecord = @$townlandsRecords[0]; // get first record
  if (!$townlandsRecord) { dieWith404("Record not found!"); } // show error message if no record found
  $townland = $townlandsRecord['num'];
?>

<?php
 // load records from 'articles' where the townland is found
  list($articlesRecords, $articlesMetaData) = getRecords(array(
    'tableName'   => 'articles',
    'loadUploads' => true,
    'perPage'     => '20',
    'where'    => 'townland LIKE "%'.$townland.'%"',
    //'debugSql'    => true, 
  ));
?>

Thanks,
Ryan

By Ryan - February 15, 2018

Ended up finding the answer here:

https://www.interactivetools.com/forum/forum-posts.php?postNum=2241468#post2241468

'where'    => 'townland LIKE "%\t'.$townland.'\t%"',