fredderick monch: PHP MySQL Tabellenproblem

Beitrag lesen

Hallo, ich habe wahrscheinlich ein Denkproblem.

Ich wollte die Webseite von meinen Eltern updaten und der Probe und Übung halber auf MySQL umstellen. Klappt soweit auch alles ganz toll, aber ich bin mit dem Code nicht so ganz zufrieden

und zwar liegt meine Table namens "wein_sorte" wie folgt vor:

idweine	wein_sorte	wein_id	wein_groesse	wein_name	wein_beschreibung	wein_preis	wein_special	zuletzt_bearbeitet  

und wird so von PHP verarbeitet:

$weinsorte = 'Trockene Rotweine 0,75l';  
// sending query  
$result = mysql_query("SELECT * FROM {$table} WHERE $sub = 'Trockene Rotweine 0,75l'");  
if (!$result) {  
    die("Query to show fields from table failed");  
}  
  
echo '<tr><td colspan="4" align="left" valign="top" width="430"><a name="Anchor-Trocken-63692"></a><span class="content2">' . $weinsorte . '<br></span><br></td></tr>';  
while($row = mysql_fetch_array($result))  
  {  
	echo '<tr>';  
	echo '<td class="pl" align="left" valign="top" width="50">' . $row['wein_id'] . ' </td>';  
	echo '<td class="pl" align="left" valign="top" width="50"><!--2007--> </td>';  
	echo '<td class="pl" align="left" valign="top" width="280"><span class="content2"><font color="black">' . $row['wein_name'] . '<br>';  
	echo '</font>';	  
	echo '</span>' . $row['wein_beschreibung'];  
	echo '<br>';  
	echo '</td>';  
	echo '<td class="pl" align="right" valign="top" width="50">' . $row['wein_preis'] . '</td>';  
	echo '</tr>';  
  }  
  
$weinsorte = 'Feinherbe Rotweine 1l';  
// sending query  
$result = mysql_query("SELECT * FROM {$table} WHERE $sub = 'Feinherbe Rotweine 1l'");  
if (!$result) {  
    die("Query to show fields from table failed");  
}  
  
echo '<tr><td colspan="4" align="left" valign="top" width="430"><a name="Anchor-Trocken-63692"></a><span class="content2">' . $weinsorte . '<br></span><br></td></tr>';  
while($row = mysql_fetch_array($result))  
  {  
	echo '<tr>';  
	echo '<td class="pl" align="left" valign="top" width="50">' . $row['wein_id'] . ' </td>';  
	echo '<td class="pl" align="left" valign="top" width="50"><!--2007--> </td>';  
	echo '<td class="pl" align="left" valign="top" width="280"><span class="content2"><font color="black">' . $row['wein_name'] . '<br>';  
	echo '</font>';	  
	echo '</span>' . $row['wein_beschreibung'];  
	echo '<br>';  
	echo '</td>';  
	echo '<td class="pl" align="right" valign="top" width="50">' . $row['wein_preis'] . '</td>';  
	echo '</tr>';  
  }  
  
$weinsorte = 'Feinherbe Rotweine 0,75l';  
// sending query  
$result = mysql_query("SELECT * FROM {$table} WHERE $sub = 'Feinherbe Rotweine 0,75l'");  
if (!$result) {  
    die("Query to show fields from table failed");  
}  
  
echo '<tr><td colspan="4" align="left" valign="top" width="430"><a name="Anchor-Trocken-63692"></a><span class="content2">' . $weinsorte . '<br></span><br></td></tr>';  
while($row = mysql_fetch_array($result))  
  {  
	echo '<tr>';  
	echo '<td class="pl" align="left" valign="top" width="50">' . $row['wein_id'] . ' </td>';  
	echo '<td class="pl" align="left" valign="top" width="50"><!--2007--> </td>';  
	echo '<td class="pl" align="left" valign="top" width="280"><span class="content2"><font color="black">' . $row['wein_name'] . '<br>';  
	echo '</font>';	  
	echo '</span>' . $row['wein_beschreibung'];  
	echo '<br>';  
	echo '</td>';  
	echo '<td class="pl" align="right" valign="top" width="50">' . $row['wein_preis'] . '</td>';  
	echo '</tr>';  
  }  
  
$weinsorte = 'Feinherbe Rotweine 1l';  
// sending query  
$result = mysql_query("SELECT * FROM {$table} WHERE $sub = 'Feinherbe Rotweine 1l'");  
if (!$result) {  
    die("Query to show fields from table failed");  
}  
  
echo '<tr><td colspan="4" align="left" valign="top" width="430"><a name="Anchor-Trocken-63692"></a><span class="content2">' . $weinsorte . '<br></span><br></td></tr>';  
while($row = mysql_fetch_array($result))  
  {  
	echo '<tr>';  
	echo '<td class="pl" align="left" valign="top" width="50">' . $row['wein_id'] . ' </td>';  
	echo '<td class="pl" align="left" valign="top" width="50"><!--2007--> </td>';  
	echo '<td class="pl" align="left" valign="top" width="280"><span class="content2"><font color="black">' . $row['wein_name'] . '<br>';  
	echo '</font>';	  
	echo '</span>' . $row['wein_beschreibung'];  
	echo '<br>';  
	echo '</td>';  
	echo '<td class="pl" align="right" valign="top" width="50">' . $row['wein_preis'] . '</td>';  
	echo '</tr>';  
  }

was im Endeffekt zwar wunderbar funktioniert, aber unglaublich hässlich ist. Jetzt ist meine Frage, wie ich das in PHP verbessern kann, dass ich nur einen Block habe und von da aus alles abgearbeitet wird oder ob ich meine SQL Datenbank (eher ungern, bin froh, dass das Teil endlich läuft und alles drin ist) neu schreiben muss. Sortiert wird wie im Code zu sehen ist nach der wein_sorte.

Vielen Dank schon im Voraus,
 Freddi