Getting last record php warning

4 posts by 3 authors in: Forums > CMS Builder
Last Post: June 22, 2020   (RSS)

By hiroko - June 20, 2020

Hi,

I am trying to use end($myRecords) to get the 'num' of the last record listed in a viewer.

The result is fine, but I have a PHP warning that says 

"Warning: Use of undefined constant     - assumed '   ' (this will throw an Error in a future version of PHP)"

I just want to get rid of the comma on the last item.

<?php // get last record num
	$lastRecord = end($itemRecords);
	$lastRecordNum = $lastRecord['num'];
?>
<?php foreach ($itemRecords as $record): ?>
some codes
<?php if ($lastRecordNum != $record['num']): ?>,<?php endif ?>
<?php endforeach ?>

Can someone tell me why I am getting this warning and how I could fix it?

Thank you,

Hiroko

By gkornbluth - June 20, 2020

Hi Hiroko,

Sorry, I don't know about the error you're getting but I've been getting rid of the last comma by using rtrim

Here's an example for some images in a list

<?php  $output ''?>

<?php foreach ($home_page_slide_showRecord['images'] as $upload)  { 
      
$output .= '{ src: ' '"' .$upload['thumbUrlPath']. '"' '}'',' 
    } 
?>

   <?php  $output rtrim($output,','); // remove trailing comma ?>

   <?php print $output?>

Hope that helps,

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 hiroko - June 22, 2020

Hi,

Thanks for the help.

I tried following Jerry's advice but couldn't figure out how to apply it to record view, not images, and have been working around, but suddenly, the error stopped when I typed in the first code again.

I guess I had something wrong somewhere.

Sorry for the fuss and thank you!

Best,

Hiroko