1

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

2 に答える 2

2

まずからキャッシュファイルを全て削除してから、を使っているのでC:\wamp\www\smarty\templates_c\このようにしてみてください。{$results[res].YOUR FIELD NAME}{section}{/section}

例えば {$results[res].question_title}

お役に立てれば幸いです。

于 2013-02-18T09:31:30.370 に答える
2

配列にキー「res」があると仮定するに変更{$results[res]}します{$results.res}

あなたの関数を見ると、次のようになるはずです:

{$results.question_title}

解決策は次のとおりです。

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