Re: [smarty] how to program this
| From: | Darius Ivanauskas | Date: | Fri, 29 Mar 2002 08:58:04 +0000 |
| Subject: | Re: [smarty] how to program this | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3393@lists.php.net to get a copy of this message | ||
On Thu, 28 Mar 2002, Uros Gruber wrote:
> Hi!
>
> below is my data from PHP
>
> And i have template file like this, and there is some values
> wich i don't know how to set them,
>
> <table>
> <tr>
> {section name=column loop=$????}
> <td>
> {section name=row loop=$???}
> name: {$????}<br>
> {/section}
> </td>
> {/section}
> </tr>
> </table>
>
> I want output like this
> <table>
> <tr>
> <td>
> name1<br>
> name2<br>
> name3<br>
> name4<br>
> </td>
> <td>
> name5<br>
> name6<br>
> name7<br>
> name8<br>
> </td>
> </tr>
> </table>
>
> So i want to know how to set this unknow values and how to
> assign in PHP, I tried something but i didn't get right
> result. I hope this is understandable i anybody can help me.
>
>
> Array
> (
> [0] => Array
> (
> [0] => Array
> (
> [id_category] => 0011
> [name] => test1
> )
>
> [1] => Array
> (
> [id_category] => 0012
> [name] => test2
> )
>
> [2] => Array
> (
> [id_category] => 0005
> [name] => test3
> )
>
> [3] => Array
> (
> [id_category] => 0006
> [name] => test4
> )
>
> )
>
> [1] => Array
> (
> [4] => Array
> (
> [id_category] => 0007
> [name] => test5
> )
>
> [5] => Array
> (
> [id_category] => 0008
> [name] => test6
> )
>
> [6] => Array
> (
> [id_category] => 0009
> [name] => test7
> )
>
> [7] => Array
> (
> [id_category] => 0010
> [name] => test8
> )
>
> )
>
>
> )
I do it the following way:
First we need to fix array indexing(use 0,1,2... instead of 4,5,6...)
$new_array = array();
foreach(array_keys($my_array) as $i)
{
$new_array[$i] = array_values($my_array[$i]);
}
$s->assign('names',$new_array);
and the template(i'm not sure if i'm using the correct variable syntax
inside section):
<table>
<tr>
{section name=column loop=$names}
<td>
{section name=row loop=$names[column]}
name: {$names[column][row].name}<br>
{/section}
</td>
{/section}
Regards
--
Darius Ivanauskas