Bin neu hier und hoffe das ich Hilfe finde bzw. eine Lösung.
Habe folgende Tabelle bzw. Anwendung und möchte für die Spalte Menge eine Summe ausgegeben haben. Weiss leider nicht genau wie das funktioniert. Habe schon etliche Tage damit verbracht es mit einer SQL-Abfrage zu schreiben, aber es klappt nicht.
Hoffe natürlich das ich hier richtig bin mit meiner Frage...
Hier mein Code:
mysql_connect($host,$user,$pass) or die("
<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\">
<tr>
<td class=\"normal-9-000000\">Keine Verbindung zur Datenbank</td>
</tr>
</table>");
mysql_select_db($db) or die("
<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\">
<tr>
<td class=\"normal-9-000000\">Datenbank nicht vorhanden</td>
</tr>
</table>");
$res = mysql_db_query("$db","select * from $table order by datum_eg desc ");
$num = mysql_num_rows($res);
echo "
<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">
<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#FEE489\">
<tr>
<td width=\"22%\" valign=\"top\" class=\"fett-12-003366\">Kunde</td>
<td width=\"19%\" valign=\"top\" class=\"fett-12-003366\">Motiv</td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\">Format</td>
<td width=\"10%\" valign=\"top\" class=\"fett-12-003366\">Termin</td>
<td width=\"9%\" valign=\"top\" class=\"fett-12-003366\">Eing.-Dat</td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\">Menge</td>
<td width=\"5%\" valign=\"top\" class=\"fett-12-003366\">Fach</td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\">Bestand</td>
<td width=\"15%\" valign=\"top\" class=\"fett-12-003366\">Bemerkung</td>
</tr>
</table>";
if ($num == 0)
{
echo "
<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">
<tr>
<td class=\"normal-9-000000\">Es befinden sich keine Einträge in der Datenbank</td>
</tr>
</table>
";
}
for ($i = 0; $i < $num; $i++)
{
$kunde = mysql_result($res, $i, "kunde");
$motiv = mysql_result($res, $i, "motiv");
$format = mysql_result($res, $i, "format");
$termin = mysql_result($res, $i, "termin");
$datum_eg = mysql_result($res, $i, "datum_eg");
$menge_eg = mysql_result($res, $i, "menge_eg");
$fach = mysql_result($res, $i, "fach");
$bestand = mysql_result($res, $i, "bestand");
$bemerkung = mysql_result($res, $i, "bemerkung");
$kunde = str_replace("\n","
",$kunde);
$kunde = str_replace("#","",$kunde);
$motiv = str_replace("\n","
",$motiv);
$motiv = str_replace("#","",$motiv);
$format = str_replace("\n","
",$format);
$format = str_replace("#","",$format);
$termin = str_replace("\n","
",$termin );
$termin = str_replace("#","",$termin );
$datum_eg = str_replace("\n","
",$datum_eg);
$datum_eg = str_replace("#","",$datum_eg);
$menge_eg = str_replace("\n","
",$menge_eg);
$menge_eg= str_replace("#","",$menge_eg);
$fach = str_replace("\n","
",$fach );
$fach = str_replace("#","",$fach );
$bestand = str_replace("\n","
",$bestand );
$bestand = str_replace("#","",$bestand );
$bemerkung = str_replace("\n","
",$bemerkung );
$bemerkung = str_replace("#","",$bemerkung );
$nr=$num-$i;
echo "
<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#FEE489\">
<tr>
<td><table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#FFFFFF\" >
<tr>
<td width=\"22%\" valign=\"top\" class=\"normal-9-000000\">$kunde</td>
<td width=\"20%\" valign=\"top\" class=\"normal-9-000000\">$motiv</td>
<td width=\"6%\" valign=\"top\" class=\"normal-9-000000\">$format</td>
<td width=\"10%\" valign=\"top\" class=\"normal-9-000000\">$termin</td>
<td width=\"10%\" valign=\"top\" class=\"normal-9-000000\">$datum_eg</td>
<td width=\"6%\" valign=\"top\" class=\"normal-9-000000\">$menge_eg</td>
<td width=\"5%\" valign=\"top\" class=\"normal-9-000000\">$fach</td>
<td width=\"6%\" valign=\"top\" class=\"normal-9-000000\">$bestand</td>
<td width=\"15%\" valign=\"top\" class=\"normal-9-000000\">$bemerkung</td>
</tr>
</table></td>
</tr>
</table>";
}
{
echo "
<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">
<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#FEE489\">
<tr>
<td width=\"22%\" valign=\"top\" class=\"fett-12-003366\">Summen</td>
<td width=\"19%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"10%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"9%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"5%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"15%\" valign=\"top\" class=\"fett-12-003366\"></td>
</tr>
</table>";
}
?>
[/php]
Habe folgende Tabelle bzw. Anwendung und möchte für die Spalte Menge eine Summe ausgegeben haben. Weiss leider nicht genau wie das funktioniert. Habe schon etliche Tage damit verbracht es mit einer SQL-Abfrage zu schreiben, aber es klappt nicht.
Hoffe natürlich das ich hier richtig bin mit meiner Frage...
Hier mein Code:
mysql_connect($host,$user,$pass) or die("
<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\">
<tr>
<td class=\"normal-9-000000\">Keine Verbindung zur Datenbank</td>
</tr>
</table>");
mysql_select_db($db) or die("
<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\">
<tr>
<td class=\"normal-9-000000\">Datenbank nicht vorhanden</td>
</tr>
</table>");
$res = mysql_db_query("$db","select * from $table order by datum_eg desc ");
$num = mysql_num_rows($res);
echo "
<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">
<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#FEE489\">
<tr>
<td width=\"22%\" valign=\"top\" class=\"fett-12-003366\">Kunde</td>
<td width=\"19%\" valign=\"top\" class=\"fett-12-003366\">Motiv</td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\">Format</td>
<td width=\"10%\" valign=\"top\" class=\"fett-12-003366\">Termin</td>
<td width=\"9%\" valign=\"top\" class=\"fett-12-003366\">Eing.-Dat</td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\">Menge</td>
<td width=\"5%\" valign=\"top\" class=\"fett-12-003366\">Fach</td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\">Bestand</td>
<td width=\"15%\" valign=\"top\" class=\"fett-12-003366\">Bemerkung</td>
</tr>
</table>";
if ($num == 0)
{
echo "
<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">
<tr>
<td class=\"normal-9-000000\">Es befinden sich keine Einträge in der Datenbank</td>
</tr>
</table>
";
}
for ($i = 0; $i < $num; $i++)
{
$kunde = mysql_result($res, $i, "kunde");
$motiv = mysql_result($res, $i, "motiv");
$format = mysql_result($res, $i, "format");
$termin = mysql_result($res, $i, "termin");
$datum_eg = mysql_result($res, $i, "datum_eg");
$menge_eg = mysql_result($res, $i, "menge_eg");
$fach = mysql_result($res, $i, "fach");
$bestand = mysql_result($res, $i, "bestand");
$bemerkung = mysql_result($res, $i, "bemerkung");
$kunde = str_replace("\n","
",$kunde);
$kunde = str_replace("#","",$kunde);
$motiv = str_replace("\n","
",$motiv);
$motiv = str_replace("#","",$motiv);
$format = str_replace("\n","
",$format);
$format = str_replace("#","",$format);
$termin = str_replace("\n","
",$termin );
$termin = str_replace("#","",$termin );
$datum_eg = str_replace("\n","
",$datum_eg);
$datum_eg = str_replace("#","",$datum_eg);
$menge_eg = str_replace("\n","
",$menge_eg);
$menge_eg= str_replace("#","",$menge_eg);
$fach = str_replace("\n","
",$fach );
$fach = str_replace("#","",$fach );
$bestand = str_replace("\n","
",$bestand );
$bestand = str_replace("#","",$bestand );
$bemerkung = str_replace("\n","
",$bemerkung );
$bemerkung = str_replace("#","",$bemerkung );
$nr=$num-$i;
echo "
<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#FEE489\">
<tr>
<td><table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#FFFFFF\" >
<tr>
<td width=\"22%\" valign=\"top\" class=\"normal-9-000000\">$kunde</td>
<td width=\"20%\" valign=\"top\" class=\"normal-9-000000\">$motiv</td>
<td width=\"6%\" valign=\"top\" class=\"normal-9-000000\">$format</td>
<td width=\"10%\" valign=\"top\" class=\"normal-9-000000\">$termin</td>
<td width=\"10%\" valign=\"top\" class=\"normal-9-000000\">$datum_eg</td>
<td width=\"6%\" valign=\"top\" class=\"normal-9-000000\">$menge_eg</td>
<td width=\"5%\" valign=\"top\" class=\"normal-9-000000\">$fach</td>
<td width=\"6%\" valign=\"top\" class=\"normal-9-000000\">$bestand</td>
<td width=\"15%\" valign=\"top\" class=\"normal-9-000000\">$bemerkung</td>
</tr>
</table></td>
</tr>
</table>";
}
{
echo "
<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">
<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#FEE489\">
<tr>
<td width=\"22%\" valign=\"top\" class=\"fett-12-003366\">Summen</td>
<td width=\"19%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"10%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"9%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"5%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"6%\" valign=\"top\" class=\"fett-12-003366\"></td>
<td width=\"15%\" valign=\"top\" class=\"fett-12-003366\"></td>
</tr>
</table>";
}
?>
[/php]
Kommentar