Problem mit Datenbank ausgabe. Dringen Hilfe benotigt

  • Themenstarter Themenstarter sinusalpha3
  • Beginndatum Beginndatum
Wochntag? auf englisch:
SQL:
DATE_FORMAT(@d1, '%W') AS w1,

Auf deutsch
SQL:
ELT(DAYOFWEEK(@d2), 'Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag') AS w2,
 
Zuletzt bearbeitet von einem Moderator:
Im Endeffekt siehts dann etwa so aus
PHP:
<?php 
//Config-File einbinden, darin wird auch die DB-Connection hergestellt
include('connect.php');
?>
<html>
<head>

</head>
<body>

<form action="" method="post" name="form" id="form">
  <p>Datum von :
    <input name="theDate_start" type="text" id="sel_start" value="<?php echo $_POST[theDate_start]; ?>" size="10" onClick="displayCalendar(document.forms[0].theDate_start,'yyyy-mm-dd',this)">
    <input type="submit" name="button2" id="button2" value="W&auml;hlen" />
  </p>
</form>
<?php


  if ($_POST[theDate_start]) {
    $datum = $_POST[theDate_start];
    
    $timestamp = strtotime($datum);
    //Array mit allen Datums bestimmen
    for($i = 0; $i <7; $i++){
        $date[] = strtotime("+{$i} day", $timestamp);
    }
    $datumSqlString = mysql_escape_string($_POST[theDate_start]);
    $sql = 
"SELECT
    id,
    @d1 AS datum1,
    MAX(IF(datum = @d1, FS, NULL)) AS FS1,
    MAX(IF(datum = @d1, SS, NULL)) AS SS1,
    MAX(IF(datum = @d1, NS, NULL)) AS NS1,
    @d2 AS datum2,
    MAX(IF(datum = @d2, FS, NULL)) AS FS2,
    MAX(IF(datum = @d2, SS, NULL)) AS SS2,
    MAX(IF(datum = @d2, NS, NULL)) AS NS2,  
    @d3 AS datum3,
    MAX(IF(datum = @d3, FS, NULL)) AS FS3,
    MAX(IF(datum = @d3, SS, NULL)) AS SS3,
    MAX(IF(datum = @d3, NS, NULL)) AS NS3,
    @d4 AS datum4,
    MAX(IF(datum = @d4, FS, NULL)) AS FS4,
    MAX(IF(datum = @d4, SS, NULL)) AS SS4,
    MAX(IF(datum = @d4, NS, NULL)) AS NS4,
    @d5 AS datum5,
    MAX(IF(datum = @d5, FS, NULL)) AS FS5,
    MAX(IF(datum = @d5, SS, NULL)) AS SS5,
    MAX(IF(datum = @d5, NS, NULL)) AS NS5,
    @d6 AS datum6,
    MAX(IF(datum = @d6, FS, NULL)) AS FS6,
    MAX(IF(datum = @d6, SS, NULL)) AS SS6,
    MAX(IF(datum = @d6, NS, NULL)) AS NS6,
    @d7 AS datum7,
    MAX(IF(datum = @d7, FS, NULL)) AS FS7,
    MAX(IF(datum = @d7, SS, NULL)) AS SS7,
    MAX(IF(datum = @d7, NS, NULL)) AS NS7
FROM
    (   SELECT
            @d1 := '{$datumSqlString}',
            @d2 := DATE_ADD(@d1, INTERVAL 1 DAY),
            @d3 := DATE_ADD(@d1, INTERVAL 2 DAY),
            @d4 := DATE_ADD(@d1, INTERVAL 3 DAY),
            @d5 := DATE_ADD(@d1, INTERVAL 4 DAY),
            @d6 := DATE_ADD(@d1, INTERVAL 5 DAY),
            @d7 := DATE_ADD(@d1, INTERVAL 6 DAY)
    ) AS vars,
    (
        SELECT 
            id,
            datum, 
            schicht, 
            if( (schicht like '%1.%' or schicht='egal'),'X','') as FS , 
            if( (schicht like '%2.%' or schicht='egal'),'X','') as SS, 
            if( (schicht like '%3.%' or schicht='egal'),'X','') as NS 
        FROM 
            eingabe 
        WHERE 
            datum BETWEEN @d1 AND @d7
    ) AS d
GROUP BY id";
  
    $result = mysql_query($sql);

    echo '<table>
          <tr>
          <th colspan="3" />';
    //Schleife um alle Tage auszugeben
    for($i = 0; $i <7; $i++){
        echo '<th colspan="3">';
        //Wochentag, ggf auf Deutsch wandeln -> googel: 'PHP Wochentag Deutsch'
        echo strftime("%A", $date[$i]);
        echo '<br />';
        //Ausgabe des Datums
        echo date('j.n.Y', $date[$i]);
        echo'</th>';    
    }
    
    echo '</tr><tr>
            <th>ID:</th>
            <th>Vorname:</th>
            <th>Nachname:</th>';
    //Schleife um für jeden Tag die Schichtnamen auszugeben 
    for($i = 0; $i<7; $i++){        
        echo '<th>FS:</th>
             <th>SS:</th>
             <th>NS:</th>';
    }
    echo '</tr>';
    
    while($row = mysql_fetch_array($result)){
        echo '<tr>';
        echo "<td>{$row['id']}</td>";  
        echo "<td>{$row['vorname']}</td>";  
        echo "<td>{$row['nachname']}</td>";  
        //Schleife um für jeden Tag die Schichten auszugeben 
        for($i = 1; $i<=7; $i++){
            echo "<td>{$row["FS{$i}"]}</td>";  
            echo "<td>{$row["SS{$i}"]}</td>";  
            echo "<td>{$row["NS{$i}"]}</td>";  
        }
        echo '</tr>';  
    }
    echo '</table>';
}
    
mysql_close();

?>
</body>
</html>
 
Hello back,

nun ich will nochmal danke sagen für die perfekte antwort.

leider habe ich ein neues Problem.

Ich möchte das jede Spalte eine andere Farbe hat.

also spalte 1 = weiß.
spalte 2 = blau.
spalte 3 = weiß.

immer abwechselnd.


ist das möglich?

Vielen dank im vorraus.
 
Also auch das habe ich hinbekommen. doch diesmal steh ich vor einem prob was ich nicht lösen kann.

dein script läuft auf der basis von php5
mein server hat aber php4.

was tun?
 
Heruausfinden welche BEfehle nicht gehen. Hab keine Lust dies für dich zu tun.
Wenn wir wissen welche Befehle, dann können wir geziehlt 4er-Alternativen suchen.
 
Ausgabe des Fehlers:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/admin/druck1.php on line 289

PHP:
while($row = mysql_fetch_array($result)){
		
		echo "<tbody>";
        echo '<tr>';
        echo "<td>{$row['id']}</td>";  
        echo "<td>{$row['nachname']}</td>"; 
        echo "<td>{$row['vorname']}</td>";   
        //Schleife um für jeden Tag die Schichten auszugeben 
        for($i = 1; $i<=8; $i++){
				if ($i % 2 == 0) {
	$farbe = "#FFFFFF";
	}
	else {
	$farbe = "#CCCCCC";
	}

auf dem alten server funktioniert es. Da ist es php5 neuer server php4.
 
PHP:
$datum = $_POST[theDate_start];
list ($jahr, $monat, $tag) = explode ("-", $datum);

$tstamp1 = mktime(date("H"),date("i"),date("s"),date($monat),date($tag)+1,date($jahr));
$tstamp2 = mktime(date("H"),date("i"),date("s"),date($monat),date(($tag)+2),date($jahr));
$tstamp3 = mktime(date("H"),date("i"),date("s"),date($monat),date($tag)+3,date($jahr));
$tstamp4 = mktime(date("H"),date("i"),date("s"),date($monat),date($tag)+4,date($jahr));
$tstamp5 = mktime(date("H"),date("i"),date("s"),date($monat),date($tag)+5,date($jahr));
$tstamp6 = mktime(date("H"),date("i"),date("s"),date($monat),date($tag)+6,date($jahr));
$tstamp7 = mktime(date("H"),date("i"),date("s"),date($monat),date($tag)+7,date($jahr));

$adddatum1 = date("Y-m-d",$tstamp1); 
$adddatum2 = date("Y-m-d",$tstamp2); 
$adddatum3 = date("Y-m-d",$tstamp3); 
$adddatum4 = date("Y-m-d",$tstamp4); 
$adddatum5 = date("Y-m-d",$tstamp5); 
$adddatum6 = date("Y-m-d",$tstamp6); 
$adddatum7 = date("Y-m-d",$tstamp7); 

  if ($_POST[theDate_start]) {
    $datum = $_POST[theDate_start];
    include ("../includes/_config.php");
    $timestamp = strtotime($datum);
    //Array mit allen Datums bestimmen
    for($i = 0; $i <8; $i++){
        $date[] = strtotime("+{$i} day", $timestamp);
    }
$sql = 
"SELECT 
    id,
	vorname,
	nachname,
	
    @d1 AS datum1,
    MAX(IF(datum = @d1, FS, NULL)) AS FS1,
    MAX(IF(datum = @d1, SS, NULL)) AS SS1,
    MAX(IF(datum = @d1, NS, NULL)) AS NS1,
    @d2 AS datum2,
    MAX(IF(datum = @d2, FS, NULL)) AS FS2,
    MAX(IF(datum = @d2, SS, NULL)) AS SS2,
    MAX(IF(datum = @d2, NS, NULL)) AS NS2,  
    @d3 AS datum3,
    MAX(IF(datum = @d3, FS, NULL)) AS FS3,
    MAX(IF(datum = @d3, SS, NULL)) AS SS3,
    MAX(IF(datum = @d3, NS, NULL)) AS NS3,
    @d4 AS datum4,
    MAX(IF(datum = @d4, FS, NULL)) AS FS4,
    MAX(IF(datum = @d4, SS, NULL)) AS SS4,
    MAX(IF(datum = @d4, NS, NULL)) AS NS4,
    @d5 AS datum5,
    MAX(IF(datum = @d5, FS, NULL)) AS FS5,
    MAX(IF(datum = @d5, SS, NULL)) AS SS5,
    MAX(IF(datum = @d5, NS, NULL)) AS NS5,
    @d6 AS datum6,
    MAX(IF(datum = @d6, FS, NULL)) AS FS6,
    MAX(IF(datum = @d6, SS, NULL)) AS SS6,
    MAX(IF(datum = @d6, NS, NULL)) AS NS6,
    @d7 AS datum7,
    MAX(IF(datum = @d7, FS, NULL)) AS FS7,
    MAX(IF(datum = @d7, SS, NULL)) AS SS7,
    MAX(IF(datum = @d7, NS, NULL)) AS NS7,
    @d7 AS datum8,
    MAX(IF(datum = @d8, FS, NULL)) AS FS8,
    MAX(IF(datum = @d8, SS, NULL)) AS SS8,
    MAX(IF(datum = @d8, NS, NULL)) AS NS8
FROM
    (   SELECT
            @d1 := '{$datumSqlString}',
            @d2 := DATE_ADD(@d1, INTERVAL 1 DAY),
            @d3 := DATE_ADD(@d1, INTERVAL 2 DAY),
            @d4 := DATE_ADD(@d1, INTERVAL 3 DAY),
            @d5 := DATE_ADD(@d1, INTERVAL 4 DAY),
            @d6 := DATE_ADD(@d1, INTERVAL 5 DAY),
            @d7 := DATE_ADD(@d1, INTERVAL 6 DAY),
			@d8 := DATE_ADD(@d1, INTERVAL 7 DAY)
    ) AS vars,
    (
        SELECT 
			id,
			vorname,
			nachname,
		    datum, 
		    schicht, 
            if( (schicht like '%1.%' or schicht='egal'),'X','') as FS , 
            if( (schicht like '%2.%' or schicht='egal'),'X','') as SS, 
            if( (schicht like '%3.%' or schicht='egal'),'X','') as NS 
        FROM 
            eingabe 
        WHERE 
            datum BETWEEN @d1 AND @d8
    ) AS d
GROUP BY nachname";

$result = mysql_query($sql);

kommt noch vor dem was ich grad gepostet habe
 
You have an error in your SQL syntax near 'SELECT @d1 := '2010-12-16', @d2 := DATE_ADD(@d1, INTERVA' at line 39

in der zeile 39
PHP:
$adddatum1 = date("Y-m-d",$tstamp1);

der rest steht ja schon oben
 
Es ist die Zeile 39 des SQL-Statements gemeint.

Du hast zu wenig im GROUP BY. Alle Felder die keine Group-Function zugewiesen sind sollten in das GROUP BY.

Ansonsten poste mal das kompilierte SQL-Stetement
Hier steht wie das geht
 
ich probiere es gerade die ganze zeit in der sql konsole

SELECT
id,
@d1 AS datum1,
MAX(IF(datum = @d1, FS, NULL)) AS FS1,
MAX(IF(datum = @d1, SS, NULL)) AS SS1,
MAX(IF(datum = @d1, NS, NULL)) AS NS1,
@d2 AS datum2,
MAX(IF(datum = @d2, FS, NULL)) AS FS2,
MAX(IF(datum = @d2, SS, NULL)) AS SS2,
MAX(IF(datum = @d2, NS, NULL)) AS NS2,
@d3 AS datum3,
MAX(IF(datum = @d3, FS, NULL)) AS FS3,
MAX(IF(datum = @d3, SS, NULL)) AS SS3,
MAX(IF(datum = @d3, NS, NULL)) AS NS3,
@d4 AS datum4,
MAX(IF(datum = @d4, FS, NULL)) AS FS4,
MAX(IF(datum = @d4, SS, NULL)) AS SS4,
MAX(IF(datum = @d4, NS, NULL)) AS NS4,
@d5 AS datum5,
MAX(IF(datum = @d5, FS, NULL)) AS FS5,
MAX(IF(datum = @d5, SS, NULL)) AS SS5,
MAX(IF(datum = @d5, NS, NULL)) AS NS5,
@d6 AS datum6,
MAX(IF(datum = @d6, FS, NULL)) AS FS6,
MAX(IF(datum = @d6, SS, NULL)) AS SS6,
MAX(IF(datum = @d6, NS, NULL)) AS NS6,
@d7 AS datum7,
MAX(IF(datum = @d7, FS, NULL)) AS FS7,
MAX(IF(datum = @d7, SS, NULL)) AS SS7,
MAX(IF(datum = @d7, NS, NULL)) AS NS7
FROM
( SELECT
@d1 := 2010-12-16,
@d2 := DATE_ADD(@d1, INTERVAL 1 DAY),
@d3 := DATE_ADD(@d1, INTERVAL 2 DAY),
@d4 := DATE_ADD(@d1, INTERVAL 3 DAY),
@d5 := DATE_ADD(@d1, INTERVAL 4 DAY),
@d6 := DATE_ADD(@d1, INTERVAL 5 DAY),
@d7 := DATE_ADD(@d1, INTERVAL 6 DAY)
) AS vars,
(
SELECT
id,
datum,
schicht,
IF( (schicht LIKE '%1.%' OR schicht='egal'),'X','') AS FS ,
IF( (schicht LIKE '%2.%' OR schicht='egal'),'X','') AS SS,
IF( (schicht LIKE '%3.%' OR schicht='egal'),'X','') AS NS
FROM
eingabe
WHERE
datum BETWEEN @d1 AND @d7
) AS d
GROUP BY id

klappt nicht
 
Zurück