I need to get some info from my database and display it in .tpl (smarty file). My sample code: PHP code:
global $smarty;
$db = Db::getInstance();
$this->_sql = 'SELECT `clientName`, `clientWebsite`, `clientFeedBack` FROM `ps_feedBackPresta` WHERE `confirm`="1" AND `approve`="1"';
$config = $db->getRow($this->_sql);
$smarty->assign('feedBacks', $config);
And my smarty code:
<a href="{$feedBacks.clientWebsite}" title="{$feedBacks.clientName}">{$feedBacks.clientName}</a><br />
{$feedBacks.clientFeedBack}
Output result:
With this code everything works fine (include with cyrillic) but when I try to output more results wiht {foreach} and this code in my .tpl:
{foreach $feedBacks as $feedBackss}
<a href="{$feedBackss.clientWebsite}" title="{$feedBackss.clientName}">{$feedBackss.clientName}</a><br />
{$feedBackss.clientFeedBack}
{/foreach}
The result is:
So where is my false and how to fix it? It's my second day of headbanging :)
BR, George :)
Print_r($config)
在数据变得聪明之前将向您显示您的数据是什么样的
I suspect the problem lies with $config = $db->getRow($this->_sql);
. You're selecting a single row, not an array of them. get all the rows and your foreach will work. When in doubt, test with $config = array($db->getRow($this->_sql));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.