|
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 |
fka Smarty n00b
Joined: 28 Apr 2012 Posts: 1
|
Posted: Sat Apr 28, 2012 7:59 pm Post subject: foreach, tablica asocjacyjna |
|
|
Mam taką tablicę:
Code: | array(7)
{
["ID"]=> string(1) "1"
["filename"]=> string(16) "Siema Testowy 01"
["extension"]=> string(3) "rar"
["size"]=> string(2) "90"
["downloadcode"]=> string(25) "1234567890123456789012345"
["uploaddate"]=> string(19) "2012-04-28 21:08:00"
["category"]=> string(9) "Testowa 1"
} |
Przeszukuje ją kodem Smarty:
Code: |
{foreach item=value from=$filelist}
<tr>
<td>{$value.extension}</td>
<td>{$value.filename}</td>
<td style="width: 140px;">{$value.category}</td>
<td style="width: 70px;">{$value.size}</td>
<td style="width: 130px;">{$value.uploaddate}</td>
</tr>
{foreachelse}
<tr>
<td rowspan="5" style="background-color: #0080FF;">There is no files.</td>
</tr>
{/foreach} |
No i otrzymuje cały czas:
Code: | <tr>
<td>1</td>
<td>1</td>
<td style="width: 140px;">1</td>
<td style="width: 70px;">1</td>
<td style="width: 130px;">1</td>
</tr>
<tr>
<td>S</td>
<td>S</td>
<td style="width: 140px;">S</td>
<td style="width: 70px;">S</td>
<td style="width: 130px;">S</td>
</tr>
<tr>
<td>r</td>
<td>r</td>
<td style="width: 140px;">r</td>
<td style="width: 70px;">r</td>
<td style="width: 130px;">r</td>
</tr>
<tr>
<td>9</td>
<td>9</td>
<td style="width: 140px;">9</td>
<td style="width: 70px;">9</td>
<td style="width: 130px;">9</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td style="width: 140px;">1</td>
<td style="width: 70px;">1</td>
<td style="width: 130px;">1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td style="width: 140px;">2</td>
<td style="width: 70px;">2</td>
<td style="width: 130px;">2</td>
</tr>
<tr>
<td>T</td>
<td>T</td>
<td style="width: 140px;">T</td>
<td style="width: 70px;">T</td>
<td style="width: 130px;">T</td>
</tr> |
Mógłby ktoś powiedzieć, dlaczego wyświetla mi się pierwsza literka każdego pola tablicy w porządku jaki występuje w tablicy? Dlaczego też ta literka przelatuje po całej pętli? Może ma ktoś jakieś solution? |
|
Back to top |
|
bordeux Smarty Rookie
Joined: 27 Jul 2010 Posts: 10
|
Posted: Wed May 30, 2012 11:06 am Post subject: |
|
|
Masz tablicę 7 elementową!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Robisz foreach
Code: |
{foreach item=value from=$filelist}
|
Cudnie, tylko przy pierwszym wywołaniu pętli $value będzie miała wartość "1", później $value "Siema Testowy 01"
W twoim przypadku $value to nie tablica (a tak na prawdę to jest string)! A traktujesz ją , tak jakby była:
|
|
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
|