Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

javascript mit array daten füllen ?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
bufffuchs
Smarty Rookie


Joined: 19 Apr 2010
Posts: 11

PostPosted: Wed Apr 21, 2010 1:39 pm    Post subject: javascript mit array daten füllen ? Reply with quote

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
View user's profile Send private message
ovnn
Smarty Regular


Joined: 14 Apr 2010
Posts: 82
Location: Germany

PostPosted: Thu Apr 22, 2010 7:11 am    Post subject: Reply with quote

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
View user's profile Send private message
bufffuchs
Smarty Rookie


Joined: 19 Apr 2010
Posts: 11

PostPosted: Thu Apr 22, 2010 10:44 am    Post subject: Reply with quote

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
View user's profile Send private message
ovnn
Smarty Regular


Joined: 14 Apr 2010
Posts: 82
Location: Germany

PostPosted: Thu Apr 22, 2010 12:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP