MYSQL Datenbank Problem

RS9999

Erfahrenes Mitglied
Hallo,

Versuche mich seit einiger Zeit in PHP und MYSQL
einzuarbeiten. Bin jetzt auf ein Problem gekommen,
dass ich leider ohne Hilfe nicht lösen kann.
Kann mir ein Profi sagen, wo der Fehler ist?
Bekomme immer alle Daten angezeigt, obwohl die URL besagt "
//////////<a href="group.php?group=<? echo $wert[0] ?>"><? u.s.w.......................//////////

Tabelle "test1" siehe bitte im Anhang "tabelle.jpg".


//////////////////////////////////Hier die Startseite mit dem CODE //////////////////////////////////////////
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>test</title>
<link href="format.css" rel="stylesheet" type="text/css" media="all">
</head>
 
<body bgcolor="#ffffff">
<div align="center">
 
<?
$link = mysql_connect("#######", "########","#######");
mysql_select_db("test", $link);
$result = mysql_query("SELECT Beruf, COUNT(ID) AS Anzahl 
FROM test1 GROUP BY Beruf ORDER BY Beruf");
$row = mysql_num_rows($result); 
 
for ($i=0; $i<$row;$i++)
{
	 $wert[] = mysql_result($result, $i,0);
	 $zahl[] = mysql_result($result, $i,1);
}
$anz= count($wert); 
 
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr height="19">
	 <td bgcolor="#339966" width="20%" height="19"><br>
	 </td>
	 <td colspan="3" bgcolor="#339966" height="19"></td>
	 <td bgcolor="#339966" width="20%" height="19"></td>
	</tr>
	<tr height="19">
<td bgcolor="#339966" width="20%" height="19"><br>
	 </td>
<td class="big" rowspan="2" colspan="3" bgcolor="#3b4f45" height="38">
	 <div align="center">&Uuml;bersicht T&auml;tikeit / Mitarbeiter</div>
	 </td>
<td bgcolor="#339966" width="20%" height="19"></td>
</tr>
	<tr height="19">
	 <td bgcolor="#339966" width="20%" height="19"><br>
	 </td>
	 <td bgcolor="#339966" width="20%" height="19"></td>
	</tr>
	<tr height="19"><?php
 
for ($i=0;$i<$anz;$i=$i+100) 
{
?>
	 <td bgcolor="#339966" width="20%" height="19"><br>
	 </td>
	 <td bgcolor="#339966" height="19"></td>
	 <td bgcolor="#339966" width="20%" height="19"></td>
	 <td bgcolor="#339966" width="20%" height="19"></td>
	 <td bgcolor="#339966" width="20%" height="19"></td>
	</tr>
	<tr height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td height="19"></td>
	 <td width="20%" height="19"></td>
	 <td width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td height="19"></td>
	 <td width="20%" height="19"></td>
	 <td width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td height="19"></td>
	 <td width="20%" height="19"></td>
	 <td width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[0] ?>"><? 
		 if ($wert [0]) {
		 echo $wert[0], " (", $zahl[0], ")"; }?></a></div>
	 </td>
	 <td width="20%" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[1] ?>"><? if ($wert [1]) {
	 echo $wert[1], " (", $zahl[1], ")"; }?></a></div>
	 </td>
	 <td width="20%" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[2] ?>"><? if ($wert [2]) {
	 echo $wert[2], " (", $zahl[2], ")"; }?>
	 </a></div>
	 </td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[3] ?>"><? if ($wert [3]) {
	 echo $wert[3], " (", $zahl[3], ")";}?></a></div>
	 </td>
	 <td width="20%" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[4] ?>"><? if ($wert [4]) {
	 echo $wert[4], " (", $zahl[4], ")";}?></a></div>
	 </td>
	 <td width="20%" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[5] ?>"><? if ($wert [5]) {
	 echo $wert[5], " (", $zahl[5], ")"; }?></a></div>
	 </td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr height="19">
	 <td bgcolor="white" width="20%" height="19"><font color="#005800"><br>
	 </font></td>
	 <td height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[6] ?>"><? if ($wert [6]) {
	 echo $wert[6], " (", $zahl[6], ")";}?></a></div>
	 </td>
	 <td width="20%" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[7] ?>"><? if ($wert [7]) {
	 echo $wert[7], " (", $zahl[7], ")";}?></a></div>
	 </td>
	 <td width="20%" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[8] ?>"><? if ($wert [8]) {
	 echo $wert[8], " (", $zahl[8], ")";}?></a></div>
	 </td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr bgcolor="#339966" height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td bgcolor="white" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[9] ?>"><? if ($wert [9]) {
	 echo $wert[9], " (", $zahl[9], ")";}?></a></div>
	 </td>
	 <td bgcolor="white" width="20%" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[10] ?>"><? if ($wert [10]) {
	 echo $wert[10], " (", $zahl[10], ")";}?></a></div>
	 </td>
	 <td bgcolor="white" width="20%" height="19">
	 <div align="center">
	 <a href="group.php?group=<? echo $wert[11] ?>"><? if ($wert [11]) {
	 echo $wert[11], " (", $zahl[11], ")";}?></a></div>
	 </td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr bgcolor="#339966" height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td bgcolor="white" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr bgcolor="#339966" height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td bgcolor="white" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr bgcolor="#339966" height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td bgcolor="white" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr bgcolor="#339966" height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td bgcolor="white" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	<tr bgcolor="#339966" height="19">
	 <td bgcolor="white" width="20%" height="19"><br>
	 </td>
	 <td bgcolor="white" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	 <td bgcolor="white" width="20%" height="19"></td>
	</tr>
	 <tr bgcolor="#339966" height="19">
	 <td width="20%" height="19"><br>
	 </td>
	 <td height="19"></td>
	 <td width="20%" height="19"></td>
	 <td width="20%" height="19"></td>
	 <td width="20%" height="19"></td>
	</tr>
</table>
</div>
</body>
 
</html>


//////////////////////////////////Hier die Seite mit dem Ergebnis//////////////////////////////////////////
////////////////Es sollen nur die zu der Gruppe gehören angezeigt werden//////////////////

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>test</title>
<link href="format.css" rel="stylesheet" type="text/css" media="all">
</head>
<body bgcolor="#ffffff">
<table width="500" border="0" cellpadding="1">
<tr>
 
<td class="kl1" bgcolor="#bed7b0" width="5%">
	 <div align="center">
	 ID</div>
	</td>
<td class="kl1" bgcolor="#bed7b0" width="25%">
	 <div align="center">
	 Vorname</div>
	</td>
<td class="kl1" bgcolor="#bed7b0" width="25%">
	 <div align="center">
	 Nachname</div>
	</td>
<td class="kl1" bgcolor="#bed7b0" width="49%">
	 <div align="center">
	 Beruf</div>
	</td>
<td class="kl1" bgcolor="#bed7b0" width="15%">
	 <div align="center">
	 Alter</div>
	</td>
 
</tr>
<?php
?>
<?php
$link = mysql_connect("#######", "#######","######");
mysql_select_db("test", $link);
$result = mysql_query ("SELECT * FROM test1 ");
$ergebnis= mysql_num_rows($result);
for ($i=0;$i<$ergebnis;$i++){
$erg1=mysql_result($result,$i,0);
$erg2=mysql_result($result,$i,1);
$erg3=mysql_result($result,$i,2);
$erg4=mysql_result($result,$i,3);
$erg5=mysql_result($result,$i,4);
 
?>
<tr>
 
<td class="kl_weiss" bgcolor="#6ea077" width="5%"><? echo $erg1;?></td>
<td class="kl_weiss" bgcolor="#6ea077" width="25%"><? echo $erg2;?></td>
<td class="kl_weiss" bgcolor="#6ea077" width="25%"><? echo $erg3;?></td>
<td class="kl_weiss" bgcolor="#6ea077" width="49%"><? echo $erg4;?></td>
<td class="kl_weiss" bgcolor="#6ea077" width="15%"><? echo $erg5;?></td>
 
</tr>
<?}?>
</table>
</body>
</html>


Würde mich sehr freuen, eine Antwort zu bekommen.

Vielen Dank.:)
 

Anhänge

  • tabelle.jpg
    tabelle.jpg
    46,5 KB · Aufrufe: 82
Zuletzt bearbeitet:
Und wo baust Du das "group" aus dem Link in Dein select Statement ein?
Habe ich das irgendwo übersehen?

redlama
 
Danke für die schnelle Antwort.



Genau da liegt noch das Problem. Versuche bereits seit einer Woche auf allen möglichen

Medien die entsprechende Lösung zu finden, jedoch ohne Erfolg!



Meine Gedanken liegen hier in der SELECT * genauer bei der WHERE- Abfrage die

im Vorfeld mit einer IF Anweisung genauer analysiert wird.

Meine Gedanken:

PHP:
$result = mysql_query ("SELECT * FROM test1 WHERE Beruf='group' " );



Versuche das Problem nochmals am Wochenende zu lösen.



Wäre aber auch sehr nett von Euch, evtl. den entsprechenden weiteren Tipp zum Thema zu posten.



Vielen Dank.
 
Du verwendest die Variable nicht, sondern schreibst den Suchbegriff group in Dein Query.
Versuche es doch mal so:
PHP:
 $result = mysql_query ("SELECT * FROM test1 WHERE Beruf='".$_GET['group']."' " );
 
Vielen Dank für die Antwort!

Leider hat Deine Lösung keine Abhilfe gebracht.

Habe jetzt nach langen Überlegungen den folgenden Code benutzt:

PHP:
$result = mysql_query ("SELECT * FROM test1 WHERE Beruf LIKE '$group' " );

Jetzt funktioniert es!

Nochmals vielen Dank an alle.

Werde auch weiterhin ein treuer User bleiben.
 
Sorry, ich habe letzte Nacht ganz verpeilt, dass man Strings mit LIKE vergleicht.

Bevor aber die nächste Frage kommt, warum das auf einem anderen Server nicht mehr funktioniert, würde ich Dir empfehlen, zumindest folgenden Teil aus meinem Beispiel zu übernehmen:
PHP:
".......-->".$_GET['group']."<--........."
Das hat mit register-globals zu tun (siehe Warnung auf "Vordefinierte Variablen").
 
Hallo,

habe mir Deine sehr guten Tipps auch noch einmal angeschaut und den Code geändert.
Danke für den Tipp, aber nur so lernt man die vielen Möglichkeiten
von MYSQL und PHP auch zu nutzen. User helfen User!

Neu:
PHP:
$result = mysql_query ("SELECT * FROM test1 WHERE Beruf LIKE '".$_GET['group']."'" );

Vielen Dank.

An der Quelle saß der Knabe, doch der Schafskopf sah Sie nicht!
 
Farbwechsel mit FOR- Schleife?

Hallo,

leider muss ich Euch nochmal nerven.:-(
Bekomme in meiner Tabelle wie gewollt
jede 2 Zeile eine andere Farbe, aber die Werte
wiederholen sich.

Liegt wohl an der FOR- Schleife,
da ohne diese alles funktioniert!

Vielen Dank für eine schnelle Rückantwort!:)

PHP:
HTML KOPF FEHLT!
 
<?
/////////////////////////////////////////////<-----Beginn Datenbankabfrage und Auswertung-------->/////////////////////////////////////////////
include("connect.inc");
mysql_select_db("shop", $link);
$seite = $_GET["seite"];
if(!isset($seite))
{
$seite = 1; 
}
$max_page =5;
$start = $seite * $max_page - $max_page;
$result = mysql_query("SELECT * FROM artikel WHERE Artikelgruppe LIKE '".$_GET['Gruppe']."'LIMIT $start,$max_page");
$row= mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
 
?>
<?php 
///////////////////////////////////////////<-- PHP Farbwechsel Modulo % 2 = jede Zeile wechseln -->////////////////////////////////// 
?>
<?
/////////////////////////////////////////////<-- Beginn PHP Farbwechsel Zeilen -->///////////////////////////////////////////////// 
?>
<?php
$colors = array ( 
// Hier die Farbangaben rein!
"#FFFFFF", 
"#D9E7EC"); 
?>
<?php
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-----Farb-Schleife= 2 * durchlaufen-------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
for ($a = 0; $a <=1; $a++){ 
?>
<? //<<<<<<--------zweite Selectabfrage für die Seitensteuerung------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
?>
<?php
$result2 = mysql_query("SELECT * FROM artikel WHERE Artikelgruppe LIKE '".$_GET['Gruppe']."' ");
$row2 = mysql_num_rows($result2);
$summ_page = ceil($row2 / $max_page);
?>
	 <tr bgcolor="<? echo $colors[$a % 2]; ?>">
<?php 
///////////////////////////////////////////<-- Ausgabe der Ergebnise in Zeilen -->////////////////////////////////// 
?>
	 <td class="kl1" width="10%"><? echo $row["ArtikelNr"] ?></td>
	 <td class="kl1" width="35%"><? echo $row["Artkelname"] ?></td>
	 <td class="kl1" width="15%"><? echo number_format($row["Preis"],2,",",".") ?></td>
	 <td class="kl1" width="20%"><? echo $row["Lieferzeit"]?></td>
	 <td width="20%"><a href='artikel.php?ArtikelNr=<? echo trim(strval($row2["ArtikelNr"])), "&Gruppe",$Gruppe ?>'><img src="images/warenkorb.jpg" alt="" height="19" width="19" border="0"></a></td> 
	 <?}?><? //<<<<<<--------ENDE WHILE SCHLEIFE 
	 ?> 
	 </tr> 
	 <?}?><? //<<<<<-------ENDE FOR SCHLEIFE 
	 ?>
	 </table>
	 <table width="99%" border="0" cellpadding="1" align="center" bgcolor="#ffffff">
	 <tr>
	 <td width="10%">
		<div align="center">
	 </div>
	 </td>
	 <td width="35%"></td>
	 <td width="15%"></td>
	 <td width="20%">
		<div align="center">
	 </div>
	 </td>
	 <td width="20%"></td>
	 </tr>
	 <tr bgcolor="#43518E">
	 <td colspan="3">
		<div align="center">
		 <a class="menue" href="index.php">&lt;&lt;&lt;&lt;&lt;---------Zur&uuml;ck zu den Artikelgruppen</a></div>
	 </td>
	 <td class="kl_weiss" colspan="2">Seitenwechsel:&nbsp; 
<?php
 
for($a=0; $a < $summ_page; $a++)
{
$b = $a + 1;
 
	 if($seite == $b)
	 {
	 echo " <b>$b</b> ";
	 }
 
	 else
	 {	 
?>
<a class="menue" href='artikelliste.php?Gruppe=<?php echo $Gruppe,"&seite=", $b; ?> '>[<?php echo $b; ?>]</a> 
<?}?><?}?>
	 </td>
	 </tr>
	 </table>
	</td>
</tr>
</table>
</body>
 
</html>
 
Zuletzt bearbeitet:
Zurück