If a record exist

5 posts by 3 authors in: Forums > CMS Builder
Last Post: February 18, 2020   (RSS)

By mbareara - February 17, 2020

Sorry for my stupid question: i would like to have a certain behaviour if "reviewRecord" exists, and another behaviour if reviewRecord doesn't exist. How can i make this?

Thank you in advance for your help

Orazio 

By mbareara - February 18, 2020

Thank You Jerry! But it doesn'work for me.

I have this code 

list($reviewRecords, $reviewMetaData) = getRecords(array(
'tableName' => 'review',
'where' => 'restaurant = ' . getNumberFromEndOfUrl(),
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$reviewRecord = @$reviewRecords[0]; // get first record

So i would like to have "no records found" 'where' => 'restaurant = ' . getNumberFromEndOfUrl(), 

Any suggestions about this?

By gkornbluth - February 18, 2020

Sorry, I thought that would work

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By kitsguru - February 18, 2020

instead of using ! (not) try using the empty function since you are testing an array.

$reviewRecord = @$reviewRecords[0]; // get first record

if (empty($reviewRecord))   {
  echo "no records found";
}
Jeff Shields