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

Daten ändern, die mit foreach ausgegeben wurden

 
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
breizh
Smarty n00b


Joined: 21 Oct 2004
Posts: 3

PostPosted: Thu Nov 25, 2004 5:45 pm    Post subject: Daten ändern, die mit foreach ausgegeben wurden Reply with quote

Hallo.

Ich habe folgendes Problem: Ich habe einen array,
Code:
$kaufteil = array(
   array("artikel" => "k21", "menge" => $baK21, "modus" => $veK21),
   array("artikel" => "k22", "menge" => $baK22, "modus" => $veK22), usw.

den ich übergebe
Code:
$smarty->assign("kt", $kaufteil);

und der mir als Tabelle ausgegeben wird:
Code:
<table>{foreach name=aussen item=kt2 from=$kt}<tr>
         {foreach key=schluessel item=wert from=$kt2}
            <td>{$schluessel}: {$wert}</td>
         {/foreach}</tr>
           {/foreach}</table>

Was ich jetzt möchte, ist folgendes: die Tabelle soll als Formular ausgegeben werden, damit Daten geändert werden können, die ich dann ans array zurückschicke, bzw. betreffende Variablen zu überschreiben.
Kann mir jemand helfen? Vielen Dank schonmal!

Gruß, Sascha
Back to top
View user's profile Send private message
T.
Smarty Regular


Joined: 22 Aug 2004
Posts: 69
Location: AT

PostPosted: Thu Nov 25, 2004 7:47 pm    Post subject: Reply with quote

Hi!

Du müsstest die werte halt in ein textfeld (<input type="text" value="{$varname}" />) schreiben und die Namen der Textfelder auch dynamisch vergeben. Dann kannst du sie einfach in PHP wieder auslesen und dort die Werte überschreiben.

mfg Thomas
_________________
Oppossom - Heavy rock from austria
Back to top
View user's profile Send private message Visit poster's website
breizh
Smarty n00b


Joined: 21 Oct 2004
Posts: 3

PostPosted: Thu Nov 25, 2004 11:59 pm    Post subject: Reply with quote

Danke für die Anwort!

Noch ne Frage (s. Code): ich möchte, das NUR die Menge über <input type="text" value="{$varname}" /> geändert werden kann, aber nicht der Artikel.
Wie müßte ich da meine Schleife anpassen?

mfg, Sascha
Back to top
View user's profile Send private message
T.
Smarty Regular


Joined: 22 Aug 2004
Posts: 69
Location: AT

PostPosted: Fri Nov 26, 2004 7:12 am    Post subject: Reply with quote

Eine Möglichkeit wäre zu überprüfen, ob der Schlüssel gleich Menge ist, also in der schleife:

{if $schluessel eq "Menge"}
<td>{$schluessel}: <input type="text" Value="{$wert}" .... /></td>
{else}
<td>{$schluessel}: {$wert}</td>
{/if}

eine andere lösung wäre, dass du deine schleife anders aufbaust und nur eine foreach machst, hab das jetz ned so genau im kopf, würds außerdem mit section machen (foreach verwend ich nie)

<table>
{section name=aussen value=$kt} //bin mir ned sicher obs value heißt
<tr>
<td>Artikel: $kt[aussen].artikel</td>
<td>Menge: <input type="text" value="$kt[aussen].artikel" ... /></td>
<td>Modus: $kt[aussen].modus</td>
</tr>
{/section}
</table>

falls dich das interessiert müsstest halt in der Docu bei Sections nachlesen oder warten bis ich wieder mal nach haus komm.

mfg Thomas
_________________
Oppossom - Heavy rock from austria
Back to top
View user's profile Send private message Visit poster's website
breizh
Smarty n00b


Joined: 21 Oct 2004
Posts: 3

PostPosted: Fri Nov 26, 2004 10:22 am    Post subject: Reply with quote

Um "$kt[aussen].artikel" und die anderen noch {} gemacht und es funzt!
Die erste Lösung geht auch. Vielen, vielen Dank!
Back to top
View user's profile Send private message
T.
Smarty Regular


Joined: 22 Aug 2004
Posts: 69
Location: AT

PostPosted: Fri Nov 26, 2004 1:03 pm    Post subject: Reply with quote

ups, ja die { } hab ich vergessen Wink
_________________
Oppossom - Heavy rock from austria
Back to top
View user's profile Send private message Visit poster's website
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