我的PHP代码输出sql的问题

时间:2012-10-08 12:59:43

标签: php sql

嘿家伙我试图连接到数据库并从表zuordnung中收集一些数据,但它不能正常我得到的一切是白页我很沮丧因为我找不到错误mabye另一双眼睛看到了这就是我到目前为止所拥有的:

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php
    include ("db_login.php");

    $link = mysql_connect($host, $user, $pass) or die ("Keine Verbindung zu der Datenbank moeglich.");
    mysql_select_db($db, $link);

    $sql = "SELECT ID_Zuordnung, HW_Typ, Hostname_alt, Username, Emailadresse, Datum_Ausgabe, Abteilung 
        FROM zuordnung
        WHERE Status_Tausch='OK' AND Status_Altgeraet='NOK'
        ORDER BY Hostname_alt;";

    $result = mysql_query($sql);
    $resultarray = mysql_fetch_array($result); 
            echo('<p>'.$resultarray['HW_Typ']."</p>");
            echo('<p>'.$resultarray['Hostname_alt']."</p>");
            echo('<p>'.$resultarray['Username']."</p>");
            echo('<p>'.$resultarray['Emailadresse']."</p>");
            echo('<p>'.$resultarray['Datum_Ausgabe']."</p>");
            echo('<p>'.$resultarray['Abteilung']."</p>");
    ?> 
 </body>
</html>

3 个答案:

答案 0 :(得分:1)

while($resultarray = mysql_fetch_array($result))
{
            echo('<p>'.$resultarray['HW_Typ']."</p>");
            echo('<p>'.$resultarray['Hostname_alt']."</p>");
            echo('<p>'.$resultarray['Username']."</p>");
            echo('<p>'.$resultarray['Emailadresse']."</p>");
            echo('<p>'.$resultarray['Datum_Ausgabe']."</p>");
            echo('<p>'.$resultarray['Abteilung']."</p>");

}

答案 1 :(得分:0)

试试这个

require_once($_SERVER['DOCUMENT_ROOT']."db_login.php");

而不是包含

如果你的记录超过1条,你需要在while循环中回显resultarray

答案 2 :(得分:0)

你忘了循环
像这样使用循环。

while($resultarray = mysql_fetch_array($result))
{
echo('<p>'.$resultarray['HW_Typ']."</p>");
            echo('<p>'.$resultarray['Hostname_alt']."</p>");
            echo('<p>'.$resultarray['Username']."</p>");
            echo('<p>'.$resultarray['Emailadresse']."</p>");
            echo('<p>'.$resultarray['Datum_Ausgabe']."</p>");
            echo('<p>'.$resultarray['Abteilung']."</p>");

}