Warning: Invalid argument supplied for foreach()

7 posts by 2 authors in: Forums > CMS Builder
Last Post: January 16, 2009   (RSS)

I've just onto a vps and whenever I try to use the code given in CMS, it doesn't show up, and I get the following error wher an image should be:

Warning: Invalid argument supplied for foreach() in /home/moonworksuk/ackatt/test2.php on line 47

Anybody have any ideas?

Thanks,

joe
High quality residential training for writers, actors & Film Making - Click Here for further information

Re: [Moonworks] Warning: Invalid argument supplied for foreach()

By Dave - January 16, 2009

Hi Joe,

That error means the variable in the foreach isn't defined. So if you had ...foreach ($record['uploads']... then maybe uploads isn't defined.

Can you attach your viewer file to this thread so we can see the code?

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

Re: [Dave] Warning: Invalid argument supplied for foreach()

Hi Dave,

The code is directly from code generator, nothing added or removed, and nothing else on the page.

<?php

require_once "/home/moonworksuk/ackatt/lib/viewer_functions.php";

list($testRecords, $testMetaData) = getRecords(array(
'tableName' => 'test',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$testRecord = @$testRecords[0]; // get first record

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>

<!-- INSTRUCTIONS -->
<div class="instructions">
<b>Sample Detail Page Viewer - Instructions:</b>
<ol>
<?php ?>
<li><b>Remove any fields you don&#39;t want displayed.</b></li>
<li>Rearrange remaining fields to suit your needs.</li>
<li>Copy and paste code into previously designed page (or add design to
this page).</li>
</ol>
</div>
<!-- /INSTRUCTIONS -->

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Test - Detail Page Viewer</h1>
Record Number: <?php echo $testRecord['num'] ?><br/>
Title: <?php echo $testRecord['title'] ?><br/>
Content: <?php echo $testRecord['content'] ?><br/>
_link : <a href="<?php echo $testRecord['_link'] ?>"><?php echo $testRecord['_link'] ?></a><br/>


<!-- STEP 2a: Display Uploads for field 'upload_image' (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 ($testRecord['upload_image'] 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 elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->


<hr/>
<?php if (!$testRecord): ?>
No record found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->

<a href="<?php echo $testMetaData['_listPage']; ?>">&lt;&lt; Back to list page</a> -
<a href="mailto:?subject=<?php echo thisPageUrl() ?>">Email this Page</a>
</body>
</html>

High quality residential training for writers, actors &amp; Film Making - Click Here for further information

Re: [Moonworks] Warning: Invalid argument supplied for foreach()

By Dave - January 16, 2009

Hi Moonworks,

Are there any records created in that section? And are any of the other fields showing their content from the database?

Let me know. Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Warning: Invalid argument supplied for foreach()

Adding info would have helped I suppose. My excuse is that it was 4am when I noticed the problem. Maybe I should have checked again before asking [:/]
High quality residential training for writers, actors &amp; Film Making - Click Here for further information

Re: [Dave] Warning: Invalid argument supplied for foreach()

all sorted, thanks
High quality residential training for writers, actors &amp; Film Making - Click Here for further information