Movie Database in PHP

fischkrampf

Mitglied
Hi,

ich schreibe gerade eine Datenbank in PHP, die Movies verwaltet. Die Datei index.php soll alle eingetragenen Movies in einer HTML-Tabelle auflisten. Leider bleiben aber die Zellen leer. Jedoch hat die Tabelle so viele Zeilen, wie es Datensätze in der MYSQL-Tabelle gibt. Ich weiss nicht wo da das Problem sein könnte...

Vielen Dank für eure Hilfe!!!!

Hier der Code:
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<?php
$owner = "fischkrampf";

$server = "localhost";
$user = "root";
$pass = "";

if((!$connection = mysql_connect($server, $user, $pass)))
        echo "Konnte nicht mit der Datenbank verbinden!";
if(!(mysql_select_db("fischkrampf", $connection)))
        echo "Konnte nicht mit der Datenbank verbinden!";

?>
<head>
<STYLE TYPE="text/css">
	body {
		font-family: Arial;
		font-size : 15px;
	}
	a {
		text-decoration : underline;
		color : Black;
		font-size : 16px;
	}
	td {

	}
	th {
		font-weight : normal;
		border-top : 1px dotted #616980;
		border-bottom : 1px dotted #616980;
	}
</STYLE>


	<title>Movie Datenbank von <?php echo $owner ?></title>
</head>

<body>
<div style="color: Navy; font-size:19px; text-align: center;">Movie Datenbank von <?php echo $owner ?></div>
<br><br><br>
<form action="mail.php" method="post">
<table border="0" align="center" cellspacing="4" cellpadding="2">
	<tr bgcolor="#e3ecf0" style="font-size: 16px; color: Navy;">
		<th align="center" onMouseOver="this.style.backgroundColor='#9abad1'" onMouseOut="this.style.backgroundColor='#e3ecf0'" width="8%"><a href="#">Bestellen</a></td>
		<th align="center" onMouseOver="this.style.backgroundColor='#9abad1'" onMouseOut="this.style.backgroundColor='#e3ecf0'" width="30%"><a href="<?php echo "$PHP_SELF?sort=name"; ?>">Filmname</a></td>
		<th align="center" onMouseOver="this.style.backgroundColor='#9abad1'" onMouseOut="this.style.backgroundColor='#e3ecf0'" width="25%"><a href="<?php echo "$PHP_SELF?sort=genre"; ?>">Genre</a></td>
		<th align="center" onMouseOver="this.style.backgroundColor='#9abad1'" onMouseOut="this.style.backgroundColor='#e3ecf0'" width="10%"><a href="<?php echo "$PHP_SELF?sort=laenge"; ?>">Länge</a></td>
		<th align="center" onMouseOver="this.style.backgroundColor='#9abad1'" onMouseOut="this.style.backgroundColor='#e3ecf0'" width="10%"><a href="<?php echo "$PHP_SELF?sort=sprache"; ?>">Sprache</a></td>
		<th align="center" onMouseOver="this.style.backgroundColor='#9abad1'" onMouseOut="this.style.backgroundColor='#e3ecf0'" width="10%"><a href="<?php echo "$PHP_SELF?sort=groesse"; ?>">Anzahl CD's</a></td>
	</tr>

<?php

$result = mysql_query("SELECT * FROM movies", $connection);
$bg = 1;

while ($row = mysql_fetch_array($result) && $result) {
	if ($bg == 1) {
		echo "<tr style='background: #E4E4E4;'><td align='center'>";
		$bg = 0;
	}
	else {
		echo "<tr style='background: Silver;'><td align='center'>";
		$bg = 1;
	}
	echo "<input type=\"checkbox\" name=\"bestellen[]\" value=\"$row[0]\"></td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td></tr>\n";
}

?>
</table>
<br><br><br><hr><br>
<table border="0" cellspacing="2" cellpadding="2" bgcolor="#EEEEEE">
<tr>
    <td width="10%">Name</td>
    <td align="center"><input type="text" name="name"></td>
    <td width="80%" align="center"></td>
</tr>
<tr>
    <td width="10%">E-Mail Adresse</td>
    <td><input type="text" name="eMail"></td>
    <td width="80%"></td>
</tr>
<tr>
    <td colspan="3"><br><input alt="Submit" type="submit" value="Anfrage senden" /><img src="pixel.gif" alt="Spacer" width="20" height="1" border="0"><input alt="Reset" type="reset" value="Formular löschen" /></td>
    <td></td>
    <td width="80%"></td>
</tr>
</table>
</form>
</body>
</html>
 
Also für mich sieht die Zeile
PHP:
while ($row = mysql_fetch_array($result) && $result) {
irgendwie ungewöhnlich aus. Kannst ja mal
PHP:
while ($row = mysql_fetch_array($result)) {
versuchen.
 
das Problem ist folgendes:

bei mysql_fetch_array() musst Du die Elemente in dem Array mit Namen ansprechen: $row[spalte1] - $row[spalte2] usw. (statt "spalte1" und "spalte2" die Spaltennamen in der MySQL-Tabelle

Du sprichst die Array-Elemente mit $row[0] - $row[1] usw. an, und das kannst Du nur wenn Du mysql_fetch_row() verwendest.

hoffe das hilft ;)


Dunsti
 
Das Problem war mit Workaholics Hilfe gelöst. Ich hätte aber nicht gedacht, dass es daran liegen könnte. Vielen Dank Workaholic!!!!

@Dunsti: Bei mysql_fetch_array() kann ich den array sowohl nummerisch, als auch assoziativ ansprechen.

optional kann ich sagen, wie ich es haben will:
mysql_fetch_array($result, konstante);

Konstanten sind:
MYSQL_BOTH - für beide Typen
MYSQL_ASSOC - für die Spaltennamen als Index
MYSQL_NUM - für Nummern
 

Neue Beiträge

Zurück