2012-07-07 49 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