Getting last record php warning

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

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

Hi Hiroko,

Generally, your code should work; the error message indicates that a "bad" whitespace character has been copied into your code. Essentially an invisible character that looks like a space or tab but isn't recognized as such by the PHP engine. One way to find the offending character is if your code editor has an option along the lines of "show hidden/invisible/non-printable characters" - with this turned it should stand out from the rest of the whitespace in your code, allowing you to delete/replace it. If you're unable to do this, I would recommend commenting/removing portions of your code until you find the line(s) that trigger the error, then re-typing that code from scratch.

Also, in addition to Jerry's method, another potentially simpler way to handle the "," could be to use a counter variable, something like this:

<?php $count = 0; ?>
<?php foreach ($itemRecords as $record): ?>
  <?php if ($count++ > 0): ?>,<?php endif; ?>
  some codes
<?php endforeach ?>

Let me know if you have any more questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

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