explode looping too much
2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 9, 2015 (RSS)
By Mohaukla - February 7, 2015
Im not sure what is going with my code but it seems to be looping on and on. See the "Features" section of this page:
http://tebben.us.r16.millsys.org/product.php?Tandem-Axle-Hydraulic-Lift-30
// load record from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => whereRecordNumberInUrl(0),
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$productsRecord = @$productsRecords[0]; // get first record
if (!$productsRecord) { dieWith404("Record not found!"); } // show error message if no record found
-------------------------------------------------------------------------------
<ul class="portfolio-details">
<li>
<p><strong>Features:</strong></p>
<ul class="list list-skills icons list-unstyled list-inline">
<?php foreach ($productsRecord as $record): ?>
<?php $lines = explode("\n", $productsRecord['product_features']); ?>
<?php foreach ($lines as $line) : ?>
<?php if($line != ''): ?>
<li><i class="fa fa-check-circle"></i><?php echo $line; ?></li>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach ?>
</ul>
</li>
</ul>
Let me know what you think.
Thanks
Michael
Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.
"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"
By Damon - February 9, 2015
HI Michael,
Can you try this code:
// load record from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => whereRecordNumberInUrl(0),
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$productsRecord = @$productsRecords[0]; // get first record
if (!$productsRecord) { dieWith404("Record not found!"); } // show error message if no record found
-------------------------------------------------------------------------------
<ul class="portfolio-details">
<li>
<p><strong>Features:</strong></p>
<ul class="list list-skills icons list-unstyled list-inline">
<?php $lines = explode("\n", $productsRecord['product_features']); ?>
<?php foreach ($lines as $line) : ?>
<?php if($line != ''): ?>
<li><i class="fa fa-check-circle"></i><?php echo $line; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</li>
</ul>
What I did was get rid of the first foreachloop. Since this is a detail page record, it looked like the additional foreachloop was returning results for all records.
Let me know if this does the trick.
Thanks!
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/