|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ZeroFill Smarty Rookie
Joined: 31 Aug 2003 Posts: 28
|
Posted: Wed Aug 27, 2008 7:07 pm Post subject: Unable to loop a simple two dimentional array |
|
|
Smarty 2.6.20
I've tried searching around and found some things that are close but this one is really baffling me.
(see notes below code)
Code: |
print_r($db_results);
//---//
Array
(
[0] => Array
(
[PROCESSSTATUS] =>
[COMPANY] => 01
[DIVISION] => 01
[CUSTEDP] => 1234
[CUSTNO] => 4567
)
[1] => Array
(
[PROCESSSTATUS] =>
[COMPANY] => 01
[DIVISION] => 01
[CUSTEDP] => 5874
[CUSTNO] => 96587
)
)
|
Code: |
<{foreach item=result from=$db_results key=server }>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<th colspan="13"><{$server}></th>
<tr>
<td>Process Status</td>
<td>Company</td>
<td>Division</td>
<td>Custedp</td>
<td>Cust #</td>
</tr>
<tr>
<td><{$result.PROCESSSTATUS}></td>
<td><{$result.COMPANY}></td>
<td><{$result.DIVISION}></td>
<td><{$result.CUSTEDP}></td>
<td><{$result.CUSTNO}></td>
</tr>
</table>
<{/foreach}>
|
If i do a
Code: |
<{$result.0.FULLORDERNO}>
|
in the foreach loop, it works. Why would I need to reference the array index?
when doing a
Code: |
<{$result|print_r}>
|
it doesn't show the index, just the list of arrays (PROCESSSTATUS, COMPANY, etc). _________________ my delimiters are <{ and }> |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Aug 27, 2008 7:24 pm Post subject: |
|
|
<{$result.0.FULLORDERNO}> ????
FULLORDERNO is not included in your print_r dump. Something does not match. Use the {debug} tag to see what is really passed to smarty. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Aug 27, 2008 7:31 pm Post subject: |
|
|
Another note to <{$result|print_r}>:
If you use modifers on a variable which is an array the modifier is executed on each single element of that array. If the modifier shall be used just once at the array itself you must use <{$result|@print_r}> . |
|
Back to top |
|
ZeroFill Smarty Rookie
Joined: 31 Aug 2003 Posts: 28
|
Posted: Wed Aug 27, 2008 7:48 pm Post subject: |
|
|
Sorry for the confusion, i meant to put $result.CUSTNO; i chopped off a bunch of array elements for simplicity.
And thanks for the @print_r tip, now I see the leading [0] array indexes.
I added another nested foreach loop and it's working great.
Thanks for the quick help U.Tews! _________________ my delimiters are <{ and }> |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Aug 27, 2008 8:28 pm Post subject: |
|
|
Or correct the way how db_results is being filled in your script. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|