2012-07-07 69 views
0

不知何故,我無法按ID列出所有的MySQL條目。結果是一個錯誤,如果我試圖通過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我只得到了最後一個條目。

回答

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);  

?> 
+0

非常感謝你。現在我知道我有我的失敗。 – kara 2012-07-07 17:12:52