【问题标题】:Displaying array data in horizontal manner using php and smarty使用php和smarty以水平方式显示数组数据
【发布时间】:2009-06-03 12:04:35
【问题描述】:

建议我一个更好的方法来做到这一点。我想以水平方式显示数组结果。

第 1 列 |第 2 栏 |第 3 列
3 | 7 | 10

现在垂直显示如下

第 1 列 |第 2 栏 |第 3 列
3
7
10


数组结果:存储在 $result 变量中并赋值给 smarty 变量

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

.tpl 代码

<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>

【问题讨论】:

  • 我认为你应该使用表结构而不是 ul 结构来做到这一点。

标签: php css loops smarty


【解决方案1】:

将 UL 置于循环之外,并确保 LI 的显示设置为内联或向左浮动。

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

【讨论】:

  • 感谢 Sleepycod。我试过。是的 li 设置为 float:left 并将 ul 放在外面但输出相同。
  • {/section}(此处)
    ”块移至此处
【解决方案2】:

这行得通吗?

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    相关资源
    最近更新 更多