dongpao5658 2013-02-18 09:19
浏览 161
已采纳

使用smarty将数组转换为错误的字符串转换

I'm trying to print an array on smarty template which I made on php. And I get this error :

Notice: Array to string conversion in C:\wamp\www\smarty\templates_c\e43b807af9cc8df7d350c3baf9e47f167c9520a0.file.index.tpl.php on line 87

I couldn't figure how to solve it. Can you tell me where is the error?

Here is the part where I make the array in php

function get_db_results()
{
    $mysql = "SELECT COUNT(*) FROM question";
    $myresult = mysql_query($mysql);
    $myr = mysql_fetch_row($myresult);
    SmartyPaginate::setTotal($myr[0]);
    $index = SmartyPaginate::getCurrentIndex();
    $limit =SmartyPaginate::getLimit();
    $rsql = "SELECT question_title FROM question ORDER BY question_id DESC LIMIT $index, $limit ";

    $rresult = mysql_query($rsql);
    //$column = array();

    while($rrow = mysql_fetch_array($rresult , MYSQL_ASSOC))
    {
        $column[]=$rrow;

    }


    return $column;
}
$smarty->assign('results', get_db_results());

And here is the smart part :

{section name=res loop=$results}
    {$results[res]}
{/section}
  • 写回答

2条回答 默认 最新

  • douqing5981 2013-02-18 09:21
    关注

    Change {$results[res]} to {$results.res} Assuming you have key "res" in your array

    By looking at your function I guess it should be :

    {$results.question_title}
    

    Here is the solution :

    {foreach from=$results item=results name=results}
        {$results.question_title}
    {/foreach}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog