0

不知何故,我无法按 ID 列出我所有的 MySQL 条目。如果我尝试按 ID 排序,结果是错误的:

Notice: Undefined variable: url_bild in /Users/fatih/Sites/phpform/neu/adressen-anzeigen.php on line 66`
Notice: Undefined variable: title in /Users/fatih/Sites/phpform/neu/adressen-anzeigen.php on line 68`

我的代码:

<?php
require_once ('konfiguration.php');

// Nutzen von Datenbank (Name ist hinterlegt in Konstante MYSQL_DATENBANK
$db_sel = mysql_select_db( MYSQL_DATENBANK )
    or die("Auswahl der Datenbank fehlgeschlagen");

$sql = " SELECT * FROM adressbuch order by id asc";
$db_erg = mysql_query( $sql );
if ( ! $db_erg )
{
    die('Ungültige Abfrage: ' . mysql_error());
}


while ($zeile = mysql_fetch_array( $db_erg, MYSQL_ASSOC))
{
    $title          = $zeile['title'];
    $description    = $zeile['description'];
    $applepart      = $zeile['applepart'];
    $partnumber     = $zeile['partnumber'];
    $productcode    = $zeile['productcode'];
    $compatibility  = $zeile['compatibility'];
    $url_bild       = $zeile['url_bild'];
    $price          = $zeile['price'];
}
mysql_free_result( $db_erg );


echo "<table id=\"products\" border=\"0\">";
echo    "<tr>"; if ( $url_bild <> "" ) {
echo        "<td class=\"thumbnail\"><img src=\"$url_bild\" /></td>"; }
echo        "<td class=\"description\"><h1>$title</h1>";
echo        "<p>$description</p>";
echo            "<table border=\"0\">";
echo                "<tr>";
echo                    "<td class=\"applepart\">Apple Part#:</td>";
echo                    "<td class=\"first\">$applepart</td>";
echo                    "<td class=\"second\">&nbsp;</td>";
echo                "</tr>";
echo                "<tr>";
echo                    "<td class=\"partnumbers\">Part Numbers:</td>";
echo                    "<td class=\"first\">$partnumber</td>";
echo                    "<td class=\"second\">&nbsp;</td>";
echo                "</tr>";
echo                "<tr>";
echo                    "<td class=\"productcode\">Product Code:</td>";
echo                    "<td class=\"first\">$productcode</td>";
echo                    "<td class=\"second\">&nbsp;</td>";
echo                "</tr>";
echo                "<tr>";
echo                    "<td class=\"compatibility\">Compatibility:</td>";
echo                    "<td class=\"first\">$compatibility</td>";
echo                    "<td class=\"second\"></td>";
echo                "</tr>";
echo        "</table>";
echo        "</td>";
echo        "<td class=\"price\"><h1>$price</h1></td>";
echo    "</tr>";
echo "</table>";

?>

如果我只是设置为SELECT * FROM adressbuch我只得到最后一个条目。

4

1 回答 1

0

固定的:

echo "<table id=\"products\" border=\"0\">";    
while ($zeile = mysql_fetch_array( $db_erg, MYSQL_ASSOC))
{
    $title          = $zeile['title'];
    $description    = $zeile['description'];
    $applepart      = $zeile['applepart'];
    $partnumber     = $zeile['partnumber'];
    $productcode    = $zeile['productcode'];
    $compatibility  = $zeile['compatibility'];
    $url_bild       = $zeile['url_bild'];
    $price          = $zeile['price'];

echo    "<tr>"; if ( $url_bild <> "" ) {
echo        "<td class=\"thumbnail\"><img src=\"$url_bild\" /></td>"; }
echo        "<td class=\"description\"><h1>$title</h1>";
echo        "<p>$description</p>";
echo            "<table border=\"0\">";
echo                "<tr>";
echo                    "<td class=\"applepart\">Apple Part#:</td>";
echo                    "<td class=\"first\">$applepart</td>";
echo                    "<td class=\"second\">&nbsp;</td>";
echo                "</tr>";
echo                "<tr>";
echo                    "<td class=\"partnumbers\">Part Numbers:</td>";
echo                    "<td class=\"first\">$partnumber</td>";
echo                    "<td class=\"second\">&nbsp;</td>";
echo                "</tr>";
echo                "<tr>";
echo                    "<td class=\"productcode\">Product Code:</td>";
echo                    "<td class=\"first\">$productcode</td>";
echo                    "<td class=\"second\">&nbsp;</td>";
echo                "</tr>";
echo                "<tr>";
echo                    "<td class=\"compatibility\">Compatibility:</td>";
echo                    "<td class=\"first\">$compatibility</td>";
echo                    "<td class=\"second\"></td>";
echo                "</tr>";
echo        "</table>";
echo        "</td>";
echo        "<td class=\"price\"><h1>$price</h1></td>";
echo    "</tr>";
}
echo "</table>";
mysql_free_result( $db_erg );    

?>
于 2012-07-07T13:30:19.780 回答