Notice: Undefined index:

3 posts by 3 authors in: Forums > CMS Builder
Last Post: July 17, 2008   (RSS)

By Kenny - July 15, 2008

Cannot figure this one out. I get an error for uploads when I try to to pull from two different tables.

Notice: Undefined index: preview_photo in /home/remaxc/public_html/index.php on line 159 Warning: Invalid argument supplied for foreach() in /home/remaxc/public_html/index.php on line 159

Notice: Undefined index: preview_photo in /home/remaxc/public_html/index.php on line 159 Warning: Invalid argument supplied for foreach() in /home/remaxc/public_html/index.php on line 159

Notice: Undefined index: preview in /home/remaxc/public_html/index.php on line 180 Warning: Invalid argument supplied for foreach() in /home/remaxc/public_html/index.php on line 180


My code is like this:
<table border="0" cellpadding="3" cellspacing="3" width="100%" id="table3">
<tr>
<td bgcolor="#CC0000">
<font color="#FFFFFF" face="Arial">Featured
Residential Properties</font></td>
</tr>
<?php foreach ($residentialRecords as $record): ?>
<tr>
<td> <?php foreach ($record['preview_photo'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php elseif ($upload['isImage']): ?>
<?php else: ?>
<?php endif ?>
<?php endforeach ?></td>
</tr>
<tr>
<td><?php echo $record['address'] ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td bgcolor="#CC0000">
<font color="#FFFFFF" face="Arial">Featured
Commercial Properties</font></td>
</tr>
<?php foreach ($commercialRecords as $record): ?>
<tr>
<td> <!-- STEP 2a: Display Uploads for field 'preview_photo' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
<?php foreach ($record['preview'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads --></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<?php endforeach; ?>
</table>


My code at the top of the page is:
<?php

require_once "/home/remaxc/public_html/webadmin/lib/viewer_functions.php";

list($residentialRecords, $residentialMetaData) = getRecords(array(
'tableName' => 'residential',
'limit' => '2',
'orderBy' => 'RAND()',
'loadUploads' => '0',
'allowSearch' => '0',
'useSeoUrls' => true,
));

list($commercialRecords, $commercialMetaData) = getRecords(array(
'tableName' => 'commercial',
'limit' => '2',
'orderBy' => 'RAND()',
'loadUploads' => '0',
'allowSearch' => '0',
'useSeoUrls' => true,
));

?>

Re: [sagentic] Notice: Undefined index:

By Dave - July 17, 2008

Hi sagentic,

Any time you get 'undefined index' it means you're trying to use a field that isn't defined. A neat trick for seeing all the fields available in a variable is this little snippet of code:

<xmp><?php print_r($record) ?></xmp>

In this case, though, both of your viewers have 'loadUploads' turned off so they're no defining the upload fields. Try removing this line from both:

'loadUploads' => '0',

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com