Jump to content

Trouble filling a Smarty array


leafface

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.