Undefined index error
2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 7, 2011 (RSS)
Hello -
Could you please help me find out why this error is occurring:
Notice: Undefined index: pdf_brochure in /usr/www/users/brother/search_details_new_canaan.php on line 102 Warning: Invalid argument supplied for foreach() in /usr/www/users/brother/search_details_new_canaan.php on line 102
The correct CMSB record is being accessed, but the inner foreach won't work...The code is directly from the CMSB code generator...Here's the code:
<?php
// determine if this listing id is in cmsb to retrieve title & body copy
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/usr/www/users/brother/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records
list($properties_for_saleRecords, $properties_for_saleMetaData) = getRecords(array(
'tableName' => 'properties_for_sale',
'loadUploads' => '0',
'allowSearch' => '0',
'where' => 'mls_number=\''.$listing_id.'\'',
));
?>
<?php foreach ($properties_for_saleRecords as $record): ?>
<?php $mls_number = $record['mls_number']; ?>
<?php $title = $record['title']; ?>
<?php $bodycopy = $record['body_copy']; ?>
<?php foreach ($record['pdf_brochure'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>
<?php endforeach ?>
<?php endforeach ?>
Thanks, Rick
Could you please help me find out why this error is occurring:
Notice: Undefined index: pdf_brochure in /usr/www/users/brother/search_details_new_canaan.php on line 102 Warning: Invalid argument supplied for foreach() in /usr/www/users/brother/search_details_new_canaan.php on line 102
The correct CMSB record is being accessed, but the inner foreach won't work...The code is directly from the CMSB code generator...Here's the code:
<?php
// determine if this listing id is in cmsb to retrieve title & body copy
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/usr/www/users/brother/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records
list($properties_for_saleRecords, $properties_for_saleMetaData) = getRecords(array(
'tableName' => 'properties_for_sale',
'loadUploads' => '0',
'allowSearch' => '0',
'where' => 'mls_number=\''.$listing_id.'\'',
));
?>
<?php foreach ($properties_for_saleRecords as $record): ?>
<?php $mls_number = $record['mls_number']; ?>
<?php $title = $record['title']; ?>
<?php $bodycopy = $record['body_copy']; ?>
<?php foreach ($record['pdf_brochure'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>
<?php endforeach ?>
<?php endforeach ?>
Thanks, Rick
Re: [rcrofoot] Undefined index error
By Jason - September 7, 2011
Hi Rick,
What the error message is saying is that there is no pdf_brochure field in your record set. The reason for this is you used the:
'loadUploads' => '0',
option, which tells the getRecords function not to include any uploads in this record set. If you remove this option, your code should work.
Hope this helps
What the error message is saying is that there is no pdf_brochure field in your record set. The reason for this is you used the:
'loadUploads' => '0',
option, which tells the getRecords function not to include any uploads in this record set. If you remove this option, your code should work.
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/