[PHP & MySQL] Verkaufspferdeauflistung inkl. Verlinkung

Kullakeeeks
php:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <link rel="stylesheet" type="text/css"
 href="style.css">
  <title>Ponyhof Ivanhoe</title>
</head>
<body>
<center>
<table width="90%">
  <tbody>
    <tr>
      <th width="15%"><b>Vorschau</b></th>
      <th width="15%"><b>Name</b></th>
      <th width="15%"><b>Rasse</b></th>
      <th width="15%"><b>Geschlecht</b></th>
      <th width="15%"><b>Alter</b></th>
      <th width="15%"><b>Preis</b></th>
    </tr>
<?php include("db.php"); $abfrage "SELECT * FROM pferd WHERE Besitzer = ''";
$ergebnis mysql_query($abfrage);
while($row -> mysql_fetch_object($ergebnis))
{ ?>
    <tr>
      <td width="15%"><?php echo " <img src="".$row->"Vorschaubild"."">";
?>
      </td>
      <td width="15%"><?php echo $row->"Name"?></td>
      <td width="15%"><?php echo $row->"Rasse"?></td>
      <td width="15%"><?php echo $row->"Geschlecht"?></td>
      <td width="15%"><?php echo $row->"Alter"?></td>
      <td width="15%"><?php echo $row->"Preis"?></td>
    </tr>
<?php ?>
  </tbody>
</table>
</center>
</body>
</html>
kext
Das Problem liegt hier:
php:
1:
echo $row->"Name";

Auf Objekteigenschaften greift man nicht mit konstanten Strings zurück. Die beste Methode ist, wie ich auch schon vorher geschrieben habe, mysql_fetch_array zu benutzen und dann so auf die Felder zuzugreifen:
php:
1:
echo $row["Name"];


Alternativ mit Objekten:
php:
1:
2:
3:
4:
5:
6:
7:
8:
9:
// RICHTIG
echo $row->Name;

// NICHT GANZ SO GUT
echo $row->{"Name"};

// ODER
$r "Name";
echo $row->$r;


Diese Zeile ist übrigens auch nicht richtig:
php:
1:
2:
3:
4:
5:
// FALSCH
while($row -> mysql_fetch_object($ergebnis))

// RICHTIG
while($row mysql_fetch_object($ergebnis))
Das war für »Fatal error: Call to a member function mysql_fetch_object() on a non-object in /users/ponyhofivanhoe/www/pferde/pony/verkaufspferde.php on line 37« verantwortlich.
Kullakeeeks
Uuuuuh, danke, es funzt smile
Vielen Dank an alle!
Kullakeeeks
Neue Frage, Startpost aktualisiert...Augenzwinkern
kext
Hallo,

beim nächsten Mal bitte einfach das Problem posten statt den Startpost zu editieren. Das erleichtert das Helfen und verstößt nicht gegen die Regeln.

Zu deinem Problem: Wenn du PHP-Steckbriefe hast, wirst du sie doch vermutlich mit steckbrief.php?id=... oder ähnlich aufrufen.

php:
1:
echo '<a href="steckbrief.php?id='.$row["id"].'">'.$row["name"].'</a>';
In deinem Code ist übrigens ein doppeltes Semikolon in Zeile 55.

lg
Kullakeeeks
Oh, okay, mach ich nächstes Mal...
Danke für deine Hilfe...

Das mit dem Semikolon hab ich auch gesehen, da es aber nicht stört, hab ich es erstmal gelassen, wenn ich den Code bearbeite nehm ichs wieder raus...