Hallo, ich lese einige Datensätze (Termine) aus einer MySQL DB aus und möchte sie dann
einem Tag zuordnen. Ich bin mittlerweile soweit, dass ich die Tage ausgelesen bekomme.
Diese werden aber nicht sortiert. Es wird alles in tmp[3] geschrieben.
PHP-Code:
error_reporting(E_ALL);
$firstweekday='20090209000001';
$lastweekday='20090213235959';
$tmp = array();
$tmp[1] = array();
$tmp[2] = array();
$tmp[3] = array();
$tmp[4] = array();
$tmp[5] = array();
$tmp[6] = array();
$db = @new mysqli('localhost', 'root', 'nwServDB', 'netacad');
if (mysqli_connect_errno()) {
die ('Konnte keine Verbindung zur Datenbank aufbauen: '.mysqli_connect_error().'('.mysqli_connect_errno().')');
}
$sql = "SELECT
UNIX_TIMESTAMP(termin_startdate) as weekday,
termin_id, termin_startdate, termin_enddate
FROM weekplan_termin WHERE termin_fach = 2
AND termin_startdate
BETWEEN '".$firstweekday."' AND '".$lastweekday."'
ORDER by termin_startdate";
$result = $db->query($sql);
if (!$result) {
die ('Etwas stimmte mit dem Query nicht: '.$db->error);
}
echo 'Die Ergebnistabelle besitzt '.$result->num_rows." Datensätze<br />\n";
while($row = $result->fetch_row()) {
$tmp[date("N",$row['termin_startdate'])][] = $row;
}
foreach ($tmp as $value){
print_r($value)."\n";
}
var_dump($result);
Hier die Ausgabe:
Array ( ) Array ( ) Array ( ) Array ( [0] => Array ( [0] => 1234162800 [1] => 1 [2] => 2009-02-09 08:00:00 [3] => 2009-02-09 11:00:00 ) [1] => Array ( [0] => 1234188000 [1] => 2 [2] => 2009-02-09 15:00:00 [3] => 2009-02-09 18:30:00 ) [2] => Array ( [0] => 1234252800 [1] => 3 [2] => 2009-02-10 09:00:00 [3] => 2009-02-10 12:00:00 ) [3] => Array ( [0] => 1234508400 [1] => 4 [2] => 2009-02-13 08:00:00 [3] => 2009-02-13 10:30:00 ) ) Array ( ) Array ( )
Außerdem bekomme ich noch die Meldung: Undefined index: termin_startdate in
der Zeile: $tmp[date("N",$row['termin_startdate'])][] = $row;
Weiß jemand Rat?