Help wih fputcsv() issue

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

By daniel - August 5

Hi Jerry,

If you check out the block of code starting around line 1479, this is where the values are being assigned to the csv row. For example:

if ($location_visible) { $csvLine[] = @$location; }

If you trace back where $location is being assigned, we find this block (lines 1081-1089):

              <?php if(($location_visible == 1)):?>
              <?php if($record['location'] ):?>
              <?php // Replace all commas with space and dash
					  $location = $record['location:label'];
					  $location = preg_replace("[,]", " -", $location); ?>
              <?php echo htmlencode($location)?>,
			    <?php else : ?>
              <?php endif ?> <?php endif ?>

As you can see, $location is only being assigned if the record has a location set. If the record doesn't have anything set for location, then the previously assigned value will remain unless the variable's value is explicitly reset (which it doesn't appear to be). I assume this is the case generally for the rest of the column values. You'll need to reset each of these variables at the top of the loop before they are to be assigned to make sure you're only using data relevant to the current record.

Let me know if this helps you out or if you have any further questions!


PHP Programmer

By gkornbluth - August 5 - edited: August 5

Hi Daniel,

Thanks for catching that. I don't think I ever would.

I tried a list of <?php $location=" " ?> and the same ideas for all the other variables after the

<?php foreach ($booksRecords as $record): ?>

on line 1067

And that worked!

Thanks as always,

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: