Image in combo viewer list

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

By Toledoh - December 2, 2012

Hi All,

I have a combo page of "products" as follows;

// load detail record from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$detailRecord = @$productsRecords[0]; // get first record
if (!$detailRecord) { dieWith404("Record not found!"); } // show error message if no record found

// load list records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'loadUploads' => false,
'allowSearch' => true,
));


and have the following code to display the navigation;

<?php foreach ($productsRecords as $listRecord): ?>
<?php $isSelected = ($listRecord['num'] == $detailRecord['num']); ?>
<li<?php if ($isSelected) { print " class='active'"; } ?>><a href="<?php echo htmlencode($listRecord['_link']) ?>">
<div class="thumb">
<img src="<?php foreach ($record['images'] as $index => $upload): ?><?php echo $upload['thumbUrlPath'] ?><?php break ?><?php endforeach ?>">
</div>
<div>
<?php echo htmlencode($listRecord['make']) ?> <?php echo htmlencode($listRecord['model']) ?><br />
Year: <?php echo htmlencode($listRecord['year']) ?><br />
Hours: <?php echo htmlencode($listRecord['hours']) ?><br />
Price: <?php echo htmlencode($listRecord['price']) ?>
</div>
</a></li>
<?php endforeach ?>


How come the image in the <div class="thumb"> isn't displaying? I get an error as Warning: Invalid argument supplied for foreach() in /home/blakem/public_html/2012/products.php on line 21 (which is the image src)
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Image in combo viewer list

Hi Tim,

I think the problem is in your foreach statement your using the variable $record, which doesn't look like it's set to anything. I think you need to change it to $listRecord['images'].

<?php foreach ($productsRecords as $listRecord): ?>
<?php $isSelected = ($listRecord['num'] == $detailRecord['num']); ?>
<li<?php if ($isSelected) { print " class='active'"; } ?>><a href="<?php echo htmlencode($listRecord['_link']) ?>">
<div class="thumb">
<img src="<?php foreach ($listRecord['images'] as $index => $upload): ?><?php echo $upload['thumbUrlPath'] ?><?php break ?><?php endforeach ?>">
</div>
<div>
<?php echo htmlencode($listRecord['make']) ?> <?php echo htmlencode($listRecord['model']) ?><br />
Year: <?php echo htmlencode($listRecord['year']) ?><br />
Hours: <?php echo htmlencode($listRecord['hours']) ?><br />
Price: <?php echo htmlencode($listRecord['price']) ?>
</div>
</a></li>
<?php endforeach ?>


Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Image in combo viewer list

By Toledoh - December 3, 2012

I tried that also Greg - no images still.

I've attached the files, the page can bee seen http://blakemachinery.com.au/2012/products.php?type=7

Thoughts?
Cheers,

Tim (toledoh.com.au)
Attachments:

products_004.php 10K

_top.php 3K

Re: [Toledoh] Image in combo viewer list

I think I've got it this time. loadUploads set to false on the getRecords function for $productRecords, setting it to true should solve the problem:

// load list records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'loadUploads' => true,
'allowSearch' => true,
));


If that doesn't fix it could you attach _globalViewers.php to a post as well?

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com