Mehrere Tabellen in MySQL auslesen

TimExtreme

Mitglied
Hi,
ich habe in einer MySQL tabelle den benutzernamen und aufgabe1, aufgabe2 ...
in den Spalten aufgabe.. ist eine 1 wenn der user die Aufgabe gelöst hat oder eine 0 wenn nicht
nun will ich dass alle tabellen die mit aufgabe beginnen ausgelesen werden und wenn es gelöst wurde soll das bild solved.gif erscheinen oder wenn nicht das bild not solved.gif


HTML:
<?php 
// Session starten 
session_start (); 


$dbuser="root";
$dbpwd="";
$dbhost="localhost";
$db="aufgaben";
$pass = md5($password);



// Aufbau der Datenbankverbindung
$connectionid  = mysql_connect ($dbhost, $dbuser, $dbpwd);
if (!mysql_select_db ("$db", $connectionid))
{
  die ("Keine Verbindung zur Datenbank");
}


//Auslesen der Benutzerdaten aus der Datenbank

$sql = "SELECT Id, Name, Points, Gesamtusr FROM aufgaben ORDER BY Id"; 
$result = mysql_query ($sql); 


$num_rows =mysql_num_rows($result);

echo "<b>Es sind $num_rows Quests in der Datenbank.</b>";
echo "</br>";
echo "</br>";
echo "<table border=1 border-color=#000000 bgcolor=#A9A9A9>\n";
echo "<tr>\n";

echo "<th bgcolor=#696969>\n";
echo "<font color=00CC00> ID</font>";
echo "</th>\n";

echo "<th bgcolor=#696969>\n";
echo "<font color=00CC00> Name</font>";
echo "</th>\n";

echo "<th bgcolor=#696969>\n";
echo "<font color=00CC00> Points</font>";
echo "</th>\n";

echo "<th bgcolor=#696969>\n";
echo "<font color=00CC00>Solved By</font>";
echo "</th>\n";

echo "<th bgcolor=#696969>\n";
echo "<font color=00CC00>Solved</font>";
echo "</th>\n";


echo "</tr>\n";
echo "<tr>\n";

while( $a_row = mysql_fetch_row( $result )){

foreach ($a_row as $field){
echo "\t<td><center><font color=#000000><b>".stripslashes($field)."</b></font></center></td>\n";
}

echo "</tr>\n";
}
echo "</table>\n";

?>

Nun soll in der Spalte solved das Bild für solved oder notsolved untereinander ausgegeben werden kann mir jemand weiterhelfen?
 
Probiers mal damit: Code ist nicht getestet:
PHP:
while( $a_row = mysql_fetch_row( $result )){
foreach ($a_row as $field){
echo "\t<td><center><font color=#000000><b>".stripslashes($field)."</b></font></center></td>\n";
}
$sql="select avg(aufgabe1+aufgabe2+...) as solved from <tabelle> where <benutzername>";
$result2 = mysql_query ($sql); 
echo '<td><img src="solved'.(floor(mysql_result($result2,0,'solved')).'.gif"'></td>';
}

Jetzt müßtest Du nur noch zwei bilder solved0.gif und solved1.gif anlegen.
Hoffe es ist das was Du brauchst.
 
Zurück