leafface Posted March 16, 2007 Share Posted March 16, 2007 Hi, i have to fill a Smarty array. The template is given, i have to create the referring php. I tried every possibilites i had in mind, but none of them work. the Smarty variables in the .tpl look tike this: {$LANG.FIRST} {$LANG.SECOND} {$LANG.THIRD} which should output: Text 1 Text 2 Text 3 The SQL table is obviously like this: idCodeText 1FIRSTText 1 2SECONDText 2 3THIRDText 3 So far, this one was my best try: $q=mysql_query("SELECT code,text FROM content_params"); $code=array(); $text=array(); while($row=mysql_fetch_row($q)) { array_push($code,$row[0]); array_push($text,$row[1]); } $smarty->assign('LANG', array( $code[0] => $text[0], $code[1] => $text[1], $code[2] => $text[2] ) ); But how do i do it with a loop, without reciting all the items? (Of course there are hundreds of items, not just three.) Please help! Link to comment https://forums.phpfreaks.com/topic/42978-trouble-filling-a-smarty-array/ Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 foreach ($text as $key => $txt) { $newArray[$code[$key]] = $txt; } $smarty->assign('LANG', $newArray); Link to comment https://forums.phpfreaks.com/topic/42978-trouble-filling-a-smarty-array/#findComment-208741 Share on other sites More sharing options...
leafface Posted March 16, 2007 Author Share Posted March 16, 2007 Thanks a million! Link to comment https://forums.phpfreaks.com/topic/42978-trouble-filling-a-smarty-array/#findComment-208746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.