foreach inside other foreach
4 posts by 3 authors in: Forums > CMS Builder
Last Post: January 13, 2009 (RSS)
By esupport - January 9, 2009
hi sir
There are two foreach in my code:
one is upload1[/#ff0080]
----------------------------------------------------------
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
<?php endforeach; ?>[/#ff0000]
----------------------------------------------------------
other is upload1More[/#ff0080]
----------------------------------
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1More'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" class="productlink01"><?php echo $upload['info1'] ?></a>
<?php endforeach ?>
<?php endforeach; ?>
-----------------------------------
I want the "upload1More" in "upload1" , like
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1'[/#ff0080]] as $upload): ?>
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1More'[/#ff0080]][/#8080ff] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" class="productlink01"><?php echo $upload['info1'] ?></a>
<?php endforeach ?>
<?php endforeach; ?>[/#000000]
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
<?php endforeach; ?>[/#ff0000]
But , I found the upload1 's thumbUrlPath is catching upload1More's thumbUrlPath.
Is it possible solve the problem?
Thanks a lot!!
-JH
There are two foreach in my code:
one is upload1[/#ff0080]
----------------------------------------------------------
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
<?php endforeach; ?>[/#ff0000]
----------------------------------------------------------
other is upload1More[/#ff0080]
----------------------------------
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1More'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" class="productlink01"><?php echo $upload['info1'] ?></a>
<?php endforeach ?>
<?php endforeach; ?>
-----------------------------------
I want the "upload1More" in "upload1" , like
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1'[/#ff0080]] as $upload): ?>
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1More'[/#ff0080]][/#8080ff] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" class="productlink01"><?php echo $upload['info1'] ?></a>
<?php endforeach ?>
<?php endforeach; ?>[/#000000]
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
<?php endforeach; ?>[/#ff0000]
But , I found the upload1 's thumbUrlPath is catching upload1More's thumbUrlPath.
Is it possible solve the problem?
Thanks a lot!!
-JH
-Jax H.
Re: [JH] foreach inside other foreach
By ross - January 9, 2009
Hi there.
Thanks for posting!
That's definitely an interesting situation. I am wondering why you needed to have it setup this way. I imagine we could try changing the variable names but that will start getting pretty advanced.
Let me know what you are trying to setup and we'll see if there are any other options that are easier to setup.
Thanks!
Thanks for posting!
That's definitely an interesting situation. I am wondering why you needed to have it setup this way. I imagine we could try changing the variable names but that will start getting pretty advanced.
Let me know what you are trying to setup and we'll see if there are any other options that are easier to setup.
Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Re: [ross] foreach inside other foreach
By esupport - January 9, 2009
hi dear sir
Here is code I have below:
-----------------------------------------------------------------------------------------
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1'] as $upload): ?>
<table width="96%" border="0" cellpadding="0" cellspacing="8">
<tr class="product-title">
<td><table width="100%" border="0" cellpadding="0" cellspacing="5">
<tr>
<td width="69%"><?php echo $upload['info1'] ?></td>
<td width="31%" align="right">
<?php foreach ($productsRecords as $record): ?>
<?php foreach ($record['upload1More'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" class="productlink01"><?php echo $upload['info1'] ?></a>
<?php endforeach ?>
<?php endforeach; ?> </td>
</tr>
</table></td>
</tr>
<tr>
<td align="right"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /></td>
</tr>
</table>
<?php endforeach ?>
<?php endforeach; ?>
-----------------------------------------------------------------------------------------
Our customer need two uploads in one content. but the scend upload is the first 'info1''s description , like "MORE..."
That's why I create other upload inside.
I am not a professional programer. I think I need your help.
Do you have any good suggesion?
Hope you can help me.
Thanks a lot from my all !
-JH
-Jax H.
Re: [JH] foreach inside other foreach
By Dave - January 13, 2009
If you want to display uploads in order from multiple uploads fields you'll need to make sure you have the same number of uploads in each field. Then you could try some code like this:
Hope that helps!
<?php for ($index = 0; $index < count($record['upload1']); $index++): ?>
<?php $upload1 = $record['upload1'][$index]; ?>
<?php $upload2 = $record['upload1More'][$index]; ?>
... display upload data here ...
<?php endfor ?>
Hope that helps!
Dave Edis - Senior Developer
interactivetools.com
interactivetools.com