我正在使用 SMARTY,我需要创建一个数组并将值分配给它的特定索引。
这是我的 php 代码:
$tag = str_replace('-', ' ',$_GET['tag']);
$tag = strip_tags(trim(mysql_real_escape_string(addslashes($tag)))); // the tags word variable
$smarty->assign('tag',$tag);
$tag_sql = "SELECT * FROM items WHERE item_published='0' AND item_tags LIKE '%$tag%' ";
$tag_query = mysql_query($tag_sql);
while ($tag_row = mysql_fetch_assoc($tag_query)) {
$items[] = $tag_row;
}
$smarty->assign('items',$items); // assign the items loop to smarty
当我在 smarty 模板中使用此代码时
{section name=x loop=$items } {$items[x].item_url} {/section}
html输出是
http://google.com http://yahoo.com
我想成为html输出
'http://google.com','http://yahoo.com'