Hallo,
ich bin blutiger Anfänger und habe in meinen Büchern und hier im Forum leider bislang nicht die richtigen Antworten gefunden.
Mein Problem ist bestimmt zu einfach...
ich habe eine Abfrage, die ich mit echo widergebe:
[COLOR=#800000][COLOR=#800000]$liste[/COLOR][/COLOR]=[COLOR=#0000f0][COLOR=#0000f0]"SELECT * FROM tabelle1 WHERE Export='0000-00-00' AND Eingang <>'0000-00-00 00:00:00' "[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000];[/COLOR]
[/COLOR][COLOR=#800000][COLOR=#800000]$liste1[/COLOR][/COLOR]=mysql_query[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$liste[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000]while[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$row[/COLOR][/COLOR]=mysql_fetch_assoc[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$liste1[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000])){[/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#0000f0][COLOR=#0000f0]echo "[/COLOR][/COLOR][COLOR=#000000]$row[/COLOR][COLOR=#0000f0][COLOR=#0000f0][ID], [/COLOR][/COLOR][COLOR=#000000]$row[/COLOR][COLOR=#0000f0][COLOR=#0000f0][Name], [/COLOR][/COLOR][COLOR=#000000]$row[/COLOR][COLOR=#0000f0][COLOR=#0000f0][KID], [/COLOR][/COLOR][COLOR=#000000]$row[/COLOR][COLOR=#0000f0][COLOR=#0000f0][KAnrede][COLOR=#0000f0][COLOR=#0000f0]<br>[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]\n[/COLOR][/COLOR][COLOR=#0000f0][COLOR=#0000f0]"[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000];[/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=#0000f0][COLOR=#0000f0][COLOR=#ff0000][COLOR=#ff0000]....[/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=black]Die Ausgabe mit "echo" klappt prima, ich erhalte alle Datensätze, die der Bedingung in der Abfrage entsprechen.[/COLOR]
[COLOR=black]Jetzt möchte ich dieses Ergebnis in eine csv-Datei packen, um es anschließend per Mail zu versenden.[/COLOR]
[COLOR=#000000]Das versuche ich mit folgendem:[/COLOR]
[COLOR=#000000][COLOR=#800000][COLOR=#800000]$fp[/COLOR][/COLOR]=fopen[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$datei[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000],[/COLOR][/COLOR][COLOR=#0000f0][COLOR=#0000f0]'w'[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR]
[/COLOR]fputs[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$fp[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000],[/COLOR][/COLOR][COLOR=#0000f0][COLOR=#0000f0]"[/COLOR][/COLOR]$row[COLOR=#0000f0][COLOR=#0000f0][ID];[/COLOR][/COLOR]$row[COLOR=#0000f0][COLOR=#0000f0][Name]"[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR][/COLOR]
[COLOR=black]fclose[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$fp[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000]}...[/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=black]Leider erhalte ich in meiner Datei nur den letzten Datensatz aus dem Array. Ich müßte also eine Schleife (wie oben vor der echo-Ausgabe) erstellen:[/COLOR][/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#000000]fputs[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$fp[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000],[/COLOR][/COLOR] (while ([COLOR=#800000][COLOR=#800000]$row[/COLOR][/COLOR]=mysql_fetch_assoc[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$liste1[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000])[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#000000][COLOR=black]bringt nur ne Fehlermeldung, die Datei bleibt leer.[/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#000000]Was mache ich falsch? Oder, wie bringe ich meine echo-Ausgabe in eine Textdatei?[/COLOR][/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#000000]Vielen Dank schon mal im voraus für Eure Zeit![/COLOR][/COLOR]
[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]
ich bin blutiger Anfänger und habe in meinen Büchern und hier im Forum leider bislang nicht die richtigen Antworten gefunden.
Mein Problem ist bestimmt zu einfach...

ich habe eine Abfrage, die ich mit echo widergebe:
[COLOR=#800000][COLOR=#800000]$liste[/COLOR][/COLOR]=[COLOR=#0000f0][COLOR=#0000f0]"SELECT * FROM tabelle1 WHERE Export='0000-00-00' AND Eingang <>'0000-00-00 00:00:00' "[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000];[/COLOR]
[/COLOR][COLOR=#800000][COLOR=#800000]$liste1[/COLOR][/COLOR]=mysql_query[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$liste[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000]while[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$row[/COLOR][/COLOR]=mysql_fetch_assoc[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$liste1[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000])){[/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#0000f0][COLOR=#0000f0]echo "[/COLOR][/COLOR][COLOR=#000000]$row[/COLOR][COLOR=#0000f0][COLOR=#0000f0][ID], [/COLOR][/COLOR][COLOR=#000000]$row[/COLOR][COLOR=#0000f0][COLOR=#0000f0][Name], [/COLOR][/COLOR][COLOR=#000000]$row[/COLOR][COLOR=#0000f0][COLOR=#0000f0][KID], [/COLOR][/COLOR][COLOR=#000000]$row[/COLOR][COLOR=#0000f0][COLOR=#0000f0][KAnrede][COLOR=#0000f0][COLOR=#0000f0]<br>[/COLOR][/COLOR][COLOR=#008000][COLOR=#008000]\n[/COLOR][/COLOR][COLOR=#0000f0][COLOR=#0000f0]"[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000];[/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=#0000f0][COLOR=#0000f0][COLOR=#ff0000][COLOR=#ff0000]....[/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=black]Die Ausgabe mit "echo" klappt prima, ich erhalte alle Datensätze, die der Bedingung in der Abfrage entsprechen.[/COLOR]
[COLOR=black]Jetzt möchte ich dieses Ergebnis in eine csv-Datei packen, um es anschließend per Mail zu versenden.[/COLOR]
[COLOR=#000000]Das versuche ich mit folgendem:[/COLOR]
[COLOR=#000000][COLOR=#800000][COLOR=#800000]$fp[/COLOR][/COLOR]=fopen[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$datei[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000],[/COLOR][/COLOR][COLOR=#0000f0][COLOR=#0000f0]'w'[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR]
[/COLOR]fputs[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$fp[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000],[/COLOR][/COLOR][COLOR=#0000f0][COLOR=#0000f0]"[/COLOR][/COLOR]$row[COLOR=#0000f0][COLOR=#0000f0][ID];[/COLOR][/COLOR]$row[COLOR=#0000f0][COLOR=#0000f0][Name]"[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR][/COLOR]
[COLOR=black]fclose[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$fp[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000]}...[/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=black]Leider erhalte ich in meiner Datei nur den letzten Datensatz aus dem Array. Ich müßte also eine Schleife (wie oben vor der echo-Ausgabe) erstellen:[/COLOR][/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#000000]fputs[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$fp[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000],[/COLOR][/COLOR] (while ([COLOR=#800000][COLOR=#800000]$row[/COLOR][/COLOR]=mysql_fetch_assoc[COLOR=#ff0000][COLOR=#ff0000]([/COLOR][/COLOR][COLOR=#800000][COLOR=#800000]$liste1[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000])[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]);[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#000000][COLOR=black]bringt nur ne Fehlermeldung, die Datei bleibt leer.[/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#000000]Was mache ich falsch? Oder, wie bringe ich meine echo-Ausgabe in eine Textdatei?[/COLOR][/COLOR][/COLOR]
[COLOR=#ff0000][COLOR=#ff0000][COLOR=#000000]Vielen Dank schon mal im voraus für Eure Zeit![/COLOR][/COLOR]
[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]
Kommentar