For each Statement help
4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 25, 2016 (RSS)
I have this code:
<?php foreach ($downloadsRecord['icon_quickship'] as $index => $upload): ?>
<td valign="top">
<a href="<?php echo $upload['urlPath'] ?>"><img src="<?php echo $upload['urlPath'] ?>" alt="" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" border="0" align="center" style="margin-bottom:5px;"/></a>
<?php if (@$downloadsRecord['quick_ship']): ?>
<?php foreach ($downloadsRecord['quick_ship'] as $index => $upload): ?>
<center>
<a href="<?php echo $upload['urlPath'] ?>" target="_blank" class="style10">Brochure</a> </center><?php endforeach ?>
<?php endif ?></td>
<?php endforeach ?>
The problem with this is that the icon (first 'a href') links to the url of the icon image. I want it to link it to the quick_ship upload url (the second 'a href')
How do I rewrite that since they are different for each statements.
By Damon - January 25, 2016 - edited: January 25, 2016
The problem with this is that the icon (first 'a href') links to the url of the icon image. I want it to link it to the quick_ship upload url (the second 'a href')
One way to solve this is to loop through the foreach to get the quick_ship upload url and assign it to a unique variable. Then use that variable as needed.
Here is the code:
<?php if (@$downloadsRecord['quick_ship']): ?>
<?php foreach ($downloadsRecord['quick_ship'] as $index => $upload): ?>
<?php $quick_ship_upload_url = $upload['urlPath']; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php foreach ($downloadsRecord['icon_quickship'] as $index => $upload): ?>
<td valign="top">
<a href="<?php echo $upload['urlPath'] ?>"><img src="<?php echo $upload['urlPath'] ?>" alt="" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" border="0" align="center" style="margin-bottom:5px;"/></a>
<?php if (@$downloadsRecord['quick_ship']): ?>
<?php foreach ($downloadsRecord['quick_ship'] as $index => $upload): ?>
<center>
<?php if($quick_ship_upload_url) : ?>
<a href="<?php echo $quick_ship_upload_url; ?>" target="_blank" class="style10">Brochure</a>
<?php endif; ?>
</center>
<?php endforeach ?>
<?php endif; ?>
</td>
<?php endforeach ?>
Try this out and let me know if this works. If it doesn't, can you provide more details.
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Thanks. Its perfect. Just some typos in the code below, like <?php endforach; ?> and <?php endif ?
But I was able to catch that. I also updated the first a href to this:
<a href="<?php echo $quick_ship_upload_url; ?>
from this:
<a href="<?php echo $upload['urlPath'] ?>">
Always a pleasure with such quick responses.
By Damon - January 25, 2016
Thanks for catching those typos.
Will slow down just a little bit with my reply next time to give the code another look over before posting. :)
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/