Webrsk
Webrsk

Reputation: 1026

Displaying array data in horizontal manner using php and smarty

Suggest me a better way to do it. I would like to show the array result in the horizontal manner.

Column1 | Column 2 | Column 3
3 | 7 | 10

now it shows in vertical manner as follows

Column1 | Column 2 | Column 3
3
7
10


Array Result : Stored in $result variable and assigned in smarty variable

Array
    (
        [0] => Array
            (
                [1] => 3
                [Value] => 3
            )
        [1] => Array
            (
                [1] => 7
                [Value] => 7
            )
        [2] => Array
            (
                [1] => 10
                [Value] => 10
            )
    )

.tpl code

<div>
    <ul>
       <li>Column1</li>
       <li>Column2</li>
       <li>Column3</li>
       <div class="clear"></div>
    </ul>

    {section name="index" loop=$result}
     <ul>                          
        <li>{$result[index].value}</li>
        <div class="clear"></div>
     </ul>
    {/section}
</div>

Upvotes: 0

Views: 2773

Answers (2)

Christophe Ebl&#233;
Christophe Ebl&#233;

Reputation: 8161

Put the UL out of your loop and make sure that LI's display is set to inline or float left.

<ul>
{section name="index" loop=$result}                     
   <li style="float:left;">{$result[index].value}</li>
{/section}
   <br style="clear:both" />
</ul>

Upvotes: 1

schnaader
schnaader

Reputation: 49729

Does this work?

<table>
 <tr>
  <th>Column1</th>
  <th>Column2</th>
  <th>Column3</th>
 </tr>

 <tr>
 {section name="index" loop=$result}
   <td>{$result[index].value}</td>
 {/section}  
 </tr>
</table>

Upvotes: 0

Related Questions