1

我正在尝试在我在 php 上制作的 smarty 模板上打印一个数组。我得到这个错误:

注意:第 87 行 C:\wamp\www\smarty\templates_c\e43b807af9cc8df7d350c3baf9e47f167c9520a0.file.index.tpl.php 中的数组到字符串转换

我想不出如何解决它。你能告诉我错误在哪里吗?

这是我在 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());

这是聪明的部分:

{section name=res loop=$results}
    {$results[res]}
{/section}
4

2 回答 2

2

更改{$results[res]}{$results.res}假设您的数组中有键“res”

通过查看您的功能,我猜它应该是:

{$results.question_title}

这是解决方案:

{foreach from=$results item=results name=results}
    {$results.question_title}
{/foreach}
于 2013-02-18T09:21:41.480 回答
2

首先删除所有缓存文件C:\wamp\www\smarty\templates_c\,然后尝试这样,{$results[res].YOUR FIELD NAME}因为您使用了{section}{/section}.

例如 {$results[res].question_title}

希望能帮到你。

于 2013-02-18T09:31:30.370 回答