Mehrdimensionales Array sortieren
Hallo,
ich habe ein Problem mit der Sortierung des folgenden Array. Die Daten kommen aus einer Datenbank und werden mit einer Schleife so in das Array geschrieben: PHP-Code:
PHP-Code:
Als Ergebnis bekomme ich bei Auslesen des Array´s folgendes zurück: 0 / 0 / 5 / 1 / RoomID / 1 0 / 0 / 5 / 2 / Description / Doppelzimmer, D / WC, Radio, TV, Telefon, Haarföhn, teilweise mit Balkon 0 / 0 / 10 / 1 / AdultDay_Price / 95.00 0 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 0 / 0 / 20 / 1 / 3Person_Price / 0 / 0 / 20 / 2 / 4Person_Price / 0 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 0 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 0 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 0 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 0 / 0 / 1 / 1 / TimeDescription / Sportwochen 0 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 0 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 1 / 0 / 5 / 1 / RoomID / 2 1 / 0 / 5 / 2 / Description / Doppelzimmer, Bad / WC, Radio, TV, Telefon, Haarföhn, teilweise mit Balkon 1 / 0 / 10 / 1 / AdultDay_Price / 97.00 1 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 1 / 0 / 20 / 1 / 3Person_Price / 1 / 0 / 20 / 2 / 4Person_Price / 1 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 1 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 1 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 1 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 1 / 0 / 1 / 1 / TimeDescription / Sportwochen 1 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 1 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 2 / 0 / 5 / 1 / RoomID / 3 2 / 0 / 5 / 2 / Description / Einbettzimmer, D / WC, Radio, TV, Telefon, Haarföhn 2 / 0 / 10 / 1 / AdultDay_Price / 95.00 2 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 2 / 0 / 20 / 1 / 3Person_Price / 2 / 0 / 20 / 2 / 4Person_Price / 2 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 2 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 2 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 2 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 2 / 0 / 1 / 1 / TimeDescription / Sportwochen 2 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 2 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 3 / 0 / 5 / 1 / RoomID / 4 3 / 0 / 5 / 2 / Description / Studiozimmer, Bad / WC, Radio, TV, Telefon, Sitzecke 3 / 0 / 10 / 1 / AdultDay_Price / 100.00 3 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 3 / 0 / 20 / 1 / 3Person_Price / 3 / 0 / 20 / 2 / 4Person_Price / 3 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 3 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 3 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 3 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 3 / 0 / 1 / 1 / TimeDescription / Sportwochen 3 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 3 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 4 / 0 / 5 / 1 / RoomID / 5 4 / 0 / 5 / 2 / Description / Appartment A 45 m2, 3 Pers. € 55,- 4 Pers. € 47,- pro Tag mit HP / Kinder 4 / 0 / 10 / 1 / AdultDay_Price / 107.00 4 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 4 / 0 / 20 / 1 / 3Person_Price / 55.00 4 / 0 / 20 / 2 / 4Person_Price / 47.00 4 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 4 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 4 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 4 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 4 / 0 / 1 / 1 / TimeDescription / Sportwochen 4 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 4 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 5 / 0 / 5 / 1 / RoomID / 6 5 / 0 / 5 / 2 / Description / Appartment B 48 m2, 3 Pers. € 63,- 4 Pers. € 55,- pro Tag mit HP / Kinder 5 / 0 / 10 / 1 / AdultDay_Price / 117.00 5 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 5 / 0 / 20 / 1 / 3Person_Price / 63.00 5 / 0 / 20 / 2 / 4Person_Price / 55.00 5 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 5 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 5 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 5 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 5 / 0 / 1 / 1 / TimeDescription / Sportwochen 5 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 5 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 Nun möchte ich das ganze nach den Spalten 3 (0 / 0 / 1 / 1 /), 1 (0 / 0 / 1 / 1 /) und 4 (0 / 0 / 1 / 1 /) sortieren, allerdings schaut das Ergebnis dann leider so aus: (hier wurde nur nach Spalte 3 (0 / 0 / 1 / 1 /) sortiert) 4 / 0 / 5 / 1 / RoomID / 5 4 / 0 / 5 / 2 / Description / Appartment A 45 m2, 3 Pers. € 55,- 4 Pers. € 47,- pro Tag mit HP / Kinder 4 / 0 / 10 / 1 / AdultDay_Price / 107.00 4 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 4 / 0 / 20 / 1 / 3Person_Price / 55.00 4 / 0 / 20 / 2 / 4Person_Price / 47.00 4 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 4 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 4 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 4 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 4 / 0 / 1 / 1 / TimeDescription / Sportwochen 4 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 4 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 5 / 0 / 5 / 1 / RoomID / 6 5 / 0 / 5 / 2 / Description / Appartment B 48 m2, 3 Pers. € 63,- 4 Pers. € 55,- pro Tag mit HP / Kinder 5 / 0 / 10 / 1 / AdultDay_Price / 117.00 5 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 5 / 0 / 20 / 1 / 3Person_Price / 63.00 5 / 0 / 20 / 2 / 4Person_Price / 55.00 5 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 5 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 5 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 5 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 5 / 0 / 1 / 1 / TimeDescription / Sportwochen 5 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 5 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 3 / 0 / 5 / 1 / RoomID / 4 3 / 0 / 5 / 2 / Description / Studiozimmer, Bad / WC, Radio, TV, Telefon, Sitzecke 3 / 0 / 10 / 1 / AdultDay_Price / 100.00 3 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 3 / 0 / 20 / 1 / 3Person_Price / 3 / 0 / 20 / 2 / 4Person_Price / 3 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 3 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 3 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 3 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 3 / 0 / 1 / 1 / TimeDescription / Sportwochen 3 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 3 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 2 / 0 / 5 / 1 / RoomID / 3 2 / 0 / 5 / 2 / Description / Einbettzimmer, D / WC, Radio, TV, Telefon, Haarföhn 2 / 0 / 10 / 1 / AdultDay_Price / 95.00 2 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 2 / 0 / 20 / 1 / 3Person_Price / 2 / 0 / 20 / 2 / 4Person_Price / 2 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 2 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 2 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 2 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 2 / 0 / 1 / 1 / TimeDescription / Sportwochen 2 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 2 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 1 / 0 / 5 / 1 / RoomID / 2 1 / 0 / 5 / 2 / Description / Doppelzimmer, Bad / WC, Radio, TV, Telefon, Haarföhn, teilweise mit Balkon 1 / 0 / 10 / 1 / AdultDay_Price / 97.00 1 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 1 / 0 / 20 / 1 / 3Person_Price / 1 / 0 / 20 / 2 / 4Person_Price / 1 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 1 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 1 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 1 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 1 / 0 / 1 / 1 / TimeDescription / Sportwochen 1 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 1 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 0 / 0 / 5 / 1 / RoomID / 1 0 / 0 / 5 / 2 / Description / Doppelzimmer, D / WC, Radio, TV, Telefon, Haarföhn, teilweise mit Balkon 0 / 0 / 10 / 1 / AdultDay_Price / 95.00 0 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 0 / 0 / 20 / 1 / 3Person_Price / 0 / 0 / 20 / 2 / 4Person_Price / 0 / 0 / 30 / 1 / 00ChildDay_Price / 45.00 0 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50 0 / 0 / 40 / 1 / 10ChildDay_Price / 55.00 0 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50 0 / 0 / 1 / 1 / TimeDescription / Sportwochen 0 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 0 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 Richtig wäre es aber so: 0 / 0 / 1 / 1 / TimeDescription / Sportwochen 0 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 0 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 1 / 0 / 1 / 1 / TimeDescription / Sportwochen 1 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00 1 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00 ........... 0 / 0 / 5 / 1 / RoomID / 1 0 / 0 / 5 / 2 / Description / Doppelzimmer, D / WC, ..... 1 / 0 / 5 / 1 / RoomID / 2 1 / 0 / 5 / 2 / Description / Doppelzimmer, Bad / WC, .... ........ 0 / 0 / 10 / 1 / AdultDay_Price / 95.00 0 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 1 / 0 / 10 / 1 / AdultDay_Price / 97.00 1 / 0 / 10 / 2 / AdultSkipass_Price / 140.00 ......... u.s.w. Was mache ich hier falsch ? :-( Zum sortieren verwende ich PHP-Code:
PHP-Code:
Besten Dank im Voraus für Eure Hilfe Leblondi |
AW: Mehrdimensionales Array sortieren
Warum überläst du das sortieren nicht der DB?
|
AW: Mehrdimensionales Array sortieren
Hallo rambi,
wenn ich die Ausgabe aus der DB so gestalten könnte, dass ich das Ergebnis direkt für die Ausgabe in Html verwenden könnte würde ich das auch machen. Die Daten müsen aber sehr komplex abgebildet werden und daher kann ich das ganze nur über ein Array lösen. (Es müssen Spalten der einzelnen Datensätze gruppiert als Zeilen ausgegeben werden, sprich die komplette Struktur der Daten muß umgeworfen werden) Kannst Du mir nicht sagen warum das sortieren nicht funktioniert ? Der Code für die Ausgabe steht schon, allerdings habe ich noch ein Problem wenn die Daten nicht sortiert ausgegeben werden. Grüße Leblondi |
AW: Mehrdimensionales Array sortieren
Zitat:
http://dev.mysql.com/doc/refman/5.1/en/index.html http://dev.mysql.com/doc/refman/5.0/en/index.html Deine Freunde heißen dann ORDER BY und GROUP BY. |
AW: Mehrdimensionales Array sortieren
Hallo meikel,
also hier noch mal meine Problemstellung: Ich lese die Daten mit dem im Screenshot -> Query.jpg angeführten Query aus und erhalte das ebenso im Screenshot gezeigte Ergebnis. Wenn Du mir sagen kannst, wie ich dieses Ergebnis als brauchbare Struktur direkt aus der Datenbank ziehen kann, bitte sehr. Ich weiß leider nicht wie das mit MySql 4.0 machbar ist. Je nachdem was der User auswählt, müssen mehrere Spalten oder mehrere Zeilen ausgegeben werden -> HTML.jpg und -> HTML2.jpg . Sobald aber mehrere Saisonen und mehrere Preisarten (Erwachsener, Kinder) ausgewählt werden stimmen die Tags für die Zeilen nicht mehr da die Ausgabe nicht sortiert ausgegegen wird (zuerst alle Erwachsenen dann alle Kinder 00 -10 dann alle Kinder bis 10 - 14). Ich hoffe hiermit mein Problem nochmal genauer beschrieben zu haben und wünsche mir helfende Ratschläge :-D Grüße Leblondi |
AW: Mehrdimensionales Array sortieren
Zitat:
Warum liest Du das Handbuch nicht einfach mal selber? |
AW: Mehrdimensionales Array sortieren
Also ihr seid hier aber echt lusitg :-D
Hast Du die meine Screenshots angesehen ???? Ich glaube eher nicht, denn dann würdest du sehen das man diese Abfrage nicht mit GROUP BY und ORder BY optimieren kann !!! Aber egal, nachdem hier nicht wirklich Hilfe bekomme werde ich meine Fragen in Zukunft in einem anderen Forum stellen, wo evntl auch jemadn auf das Problem eingeht !! Ich finde es witzig das sogenannte GURUS nicht mal auf ein Problem eingehen können sondern nur blöde Sprüche klopfen :-D Grüße Leblondi |
AW: Mehrdimensionales Array sortieren
Zitat:
Was mich wirklich interessiert hätte, wären das CREATE TABLE, ein paar Beispieldatensätze und eine konkrete Beschreibung der Aufgabe. Stattdessen lieferst Du unübersichtlichen Buchstabenmüll. Zitat:
Zitat:
|
AW: Mehrdimensionales Array sortieren
Zitat:
|
Alle Zeitangaben in WEZ +2. Es ist jetzt 11:51:53 Uhr. |
Powered by vBulletin® Version 3.8.3 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.