2014-09-22 4 views
0

SMARTY를 사용하고 있는데 배열을 만들고 특정 인덱스에 값을 할당해야합니다.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 

내가 유식 템플릿에이 코드를 사용

{section name=x loop=$items } {$items[x].item_url} {/section} 

HTML 출력 내가 HTML 출력

되고 싶어

http://google.com http://yahoo.com 

입니다

'http://google.com','http://yahoo.com' 
+0

당신이 무엇을 달성하고자 불분명하다. 질문을 편집하고 PHP에서 데이터가 무엇인지 보여줄 수 있습니다. 이제 원하는 것을 말하기가 정말 어렵습니다. –

답변

0

귀하는이 방법을 수행 할 수 있습니다 그것에 대해

{section name=x loop=$items } {append var="urls" value="'`$items[x].item_url`'"} {/section} 

{","|implode:$urls} 

출력은 다음과 같습니다

'http://google.com','http://yahoo.com' 

는 멋지 2의 경우 다음을 사용할 수 있습니다

{section name=x loop=$items } '{$items[x].item_url}'{if not $smarty.section.x.last},{/if} {/section} 
+0

다음 오류가 발생했습니다. 치명적 오류 : Smarty 오류 : [tag.html의 44 번째 줄] : 구문 오류 : C : \ wamp \ www \ include \ smarty \ apprec에있는 'append'(Smarty_Compiler.class.php, line 590) Smarty.class.php on line 1095 – user3778067

+0

@ user3778067 오류를 붙여 넣지 않았습니다. Smarty의 어떤 버전을 사용하십니까? –

+0

@version 2.6.18 – user3778067

관련 문제