Eurokicker
-


Hinweise


Antwort
 
LinkBack Themen-Optionen Thema durchsuchen Thema bewerten
Alt 24.02.2003, 17:11   #1
TP-Veteran
 
Benutzerbild von Flow09
 
Registriert seit: Jun 2001
Ort: Wien
Flow09 ist auf einem guten Weg
Unhappy

SQL-String aus Array-Daten zusammensetzen


OK! Es kann sein das ich das jetzt total falsch angegangen bin.

Ich möchte einen SQL-String aus Array-Daten zusammensetzen!

So schaut das aus was ich jetzt fabriziert habe!

PHP-Code:
$ret array_keys($feld);

$sql "INSERT INTO Usergroups (".    
foreach (
$ret as $var)
{
echo 
$var.",";
}
.
") VALUES (".
foreach (
$feld as $var2)
{
echo 
" ' ".$var2." ', ";
}
.
")"
Schaut ziemlich wild aus, ich weiß aber ich hab keine Ahnung wie ich's sonst machen soll!

Fehlermeldung ist: Parse error: parse error in /usr/local/httpd/.../newGroup.php on line 21

Line 21 ist beim ersten foreach!!

lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
Flow09 ist offline   Mit Zitat antworten


Alt 24.02.2003, 17:16   #2
TP-Greis
 
Benutzerbild von Boris
 
Registriert seit: Mar 2001
Ort: Berlin, Germany
Boris ist ein richtiges Arbeitstier - DANKEBoris ist ein richtiges Arbeitstier - DANKEBoris ist ein richtiges Arbeitstier - DANKEBoris ist ein richtiges Arbeitstier - DANKEBoris ist ein richtiges Arbeitstier - DANKEBoris ist ein richtiges Arbeitstier - DANKE
Ich mach das so ähnllich:

PHP-Code:
if ($_POST['submit'])
{
foreach(
$_POST['deinarray'] AS $key => $val) {
  
$tmpsql .= "$key = '$val',";
}

$tmpsql substr($tmpsql,0,strlen($tmpsql)-1);
$query="UPDATE tabelle SET $tmpsql";
echo 
$query;

__________________
My software never has bugs. It just develops random features ...

» DevShack - die Website des freien Webentwicklers Boris
Boris ist offline   Mit Zitat antworten
Alt 24.02.2003, 17:16   #3
TP-Moderator
 
Benutzerbild von Stuck Mojo
 
Registriert seit: Feb 2001
Ort: Helmstedt/Wolfsburg
Stuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKE
PHP-Code:
foreach($arrayname as $key => $var) {
   
$tmp[] = $key ."='".$var."'";
}
$sql "INSERT INTO Usergroups SET ".implode(',',$tmp); 
SET in einem INSERT funzt aber nur in MySQL... soweit ich weiss

Gruss
Jan
Stuck Mojo ist offline   Mit Zitat antworten
Alt 24.02.2003, 17:21   #4
TP-Veteran
 
Benutzerbild von Flow09
 
Registriert seit: Jun 2001
Ort: Wien
Flow09 ist auf einem guten Weg
Question

@adagio: Kannst Du mir das kurz ein bisschen aufschlüsseln, ich werd daraus jetzt nicht ganz schlau!

Danke!

Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
Flow09 ist offline   Mit Zitat antworten
Alt 24.02.2003, 17:29   #5
TP-Veteran
 
Benutzerbild von Flow09
 
Registriert seit: Jun 2001
Ort: Wien
Flow09 ist auf einem guten Weg
Super! Ich bin ganz begeistert!

Stuck Mojo hat's geschaft!!

Funktioniert einwandfrei!

Danke (mit großer verneigung)!

lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
Flow09 ist offline   Mit Zitat antworten
Alt 24.02.2003, 17:31   #6
TP-Moderator
 
Benutzerbild von Stuck Mojo
 
Registriert seit: Feb 2001
Ort: Helmstedt/Wolfsburg
Stuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKE
Das sind beides die gleichen Scripte, nur dass meinst über ein temporäres Array arbeitet und Adagios den String direkt zusammen setzt.
Stuck Mojo ist offline   Mit Zitat antworten
Antwort

  Aktuelles Thema
  TP Hilfe Forum > Web-Editoren & Coding > Traum-Dynamik
SQL-String aus Array-Daten zusammensetzen SQL-String aus Array-Daten zusammensetzen
« Übergebene Felder in Array speichern | Komma und Punkte bei Query, Form Variablen Reihenfolge »

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 03:17 Uhr.

Powered by: vBulletin Version 3.7 (Deutsch)
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. / Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Traum-Projekt.com | Suchen | Archiv | Impressum | Kontakt | | | Nach oben |



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67