|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bufffuchs Smarty Rookie
Joined: 19 Apr 2010 Posts: 11
|
Posted: Wed Apr 21, 2010 1:39 pm Post subject: javascript mit array daten füllen ? |
|
|
hy
ich habe eine problem
ich übergebe aus einer php datei ein array inhalt an eine tpl.
in der tpl ist ein javascript was mit den inhalten des arrays gefüttert werden soll.
wie stelle ich es an. mit literal geht es ja nicht |
|
Back to top |
|
ovnn Smarty Regular
Joined: 14 Apr 2010 Posts: 82 Location: Germany
|
Posted: Thu Apr 22, 2010 7:11 am Post subject: |
|
|
ich würde das PHP array vor der Übergabe an das Template in einen string umwandeln und dann einfach nur noch in smarty ausgeben. |
|
Back to top |
|
bufffuchs Smarty Rookie
Joined: 19 Apr 2010 Posts: 11
|
Posted: Thu Apr 22, 2010 10:44 am Post subject: |
|
|
versteh ich nicht ganz.
ich poste mal mein code
Code: | $result1=mysql_query("SELECT
idf1_strecke,
name,
länge,
breite
from $strecke
where saison_strecke = 2010
");
echo mysql_error();
$goo = array();
while($row=mysql_fetch_assoc($result1)){
array_push($goo,$row);
}
$smarty->assign('goo',$goo);
|
in $goo stehen die daten bereit in ich ans tpl wo das java drin ist übergeben möchte |
|
Back to top |
|
ovnn Smarty Regular
Joined: 14 Apr 2010 Posts: 82 Location: Germany
|
Posted: Thu Apr 22, 2010 12:33 pm Post subject: |
|
|
dann hast du in $goo
Strukturmäßig dieses
[zeile1][spalte1]= wert
[zeile1][spalte2]= wert
[zeile2][spalte1]= wert
[zeile2][spalte2]= wert
usw
wenn du das array nur für JS brauchst. Würde ich es gleich so schreiben, also in php nicht als array sondern als JS quellcode String in einer Var
bsp
Code: | $jscode = 'myjsarr[1] = new Array(); myjsarr[1][1] = '.$row['idf1_strecke'].'; myjsarr[1][2] = '.$row['name'].';';
$smarty->assign('jscode',$jscode);
|
im tpl dann
{$jscode}
Außerdem würde ich umlaute in Mysql Spaltennamen vermeiden das macht nur Probleme |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|