2013-07-21 44 views
-2

任何人都知道爲什麼我的$result回聲在頁腳而不是正文?它是一個HTML也許div問題或PHP?PHP回聲在頁腳而不是正文

這裏是相似,我有一個東西:

<?php 
     // 1. Create a database connection 
     $dbhost = "localhost"; 
     $dbuser = "tester"; 
     $dbpass = "12345"; 
     $dbname = "practice"; 
     $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); 
     // Test if connection occurred. 
     if(mysqli_connect_errno()) { 
     die("Database connection failed: " . 
      mysqli_connect_error() . 
      " (" . mysqli_connect_errno() . ")" 
     ); 
     } 
    ?> 

    <?php 
    // 2. Perform database query 
    $SQLstring = "SELECT *FROM user ORDER BY username"; 


    // Test if there was a query error 
    $QueryResult = @mysqli_query($connection, $SQLstring) 
    Or die("<p>Unable to execute query.</p>" 
    . "<p>Error code " . mysqli_errno($connection) 
    . ": " . mysqli_error($connection)) . "</p>"; 

    ?> 

    <!DOCTYPE> 
    <html> 
    <head> 
    </head> 
    <body> 
    <?php 
    //3. uses the mysqli_assoc() to print table 
    echo "<table>"; 
    echo "<tr><th>Name</th><th>Address</th><th bgcolor='#0099FF' 
      align='left'>City</th><th bgcolor='#0099FF' align='left'>State</th></tr>";     
    $num_results = $QueryResult->num_rows; 

    for ($i=0; $i <$num_results; $i++) { 
    // 3. Use returned data (if any) 
    $Row = mysqli_fetch_assoc($QueryResult); //associative array 

    // output data from each row 

    echo "<tr><td>{$Row['username']}</td>"; 
    echo "<td>{$Row['address']}</td>"; 
    echo "<td>{$Row['city']}</td>"; 
    echo "<td>{$Row['state']}</td>"; 
    </tr>"; 
    } 

    // 4. Release returned data - close query 
    mysqli_free_result($QueryResult);       
    ?> 
    </body> 
    </html> 

    <?php 
     // 5. Close database connection 
     mysqli_close($connection); 
    ?> 

任何想法?表格打印出來沒有問題,只是沒有在網站上的正確位置

+0

你可以把打印屏幕並上傳? – 2013-07-21 07:04:54

+1

您錯過了'',但我不認爲這會導致此問題。 – Barmar

+1

我在您發佈的代碼中看不到'$ result'或頁腳。 – Sean

回答

1
echo "<td>{$Row['city']}</td>"; 
    echo "<td>{$Row['state']}</td>"; 
    </tr>"; //You got an error here! 
    } 

我想你忘了迴應此行。

+1

我懷疑這是複製到SO的錯誤,否則由於解析錯誤,腳本根本無法運行。 – Barmar

+0

謝謝是的,我現在看到它了......哦,我的..forgot關閉一個表..一個錯誤......感謝Darick – user2603638

0

你應該得到解析錯誤,但我不能指出這一點

只是試圖改變這一行

// output data from each row 

echo "<tr><td>{$Row['username']}</td>"; 
echo "<td>{$Row['address']}</td>"; 
echo "<td>{$Row['city']}</td>"; 
echo "<td>{$Row['state']}</td>"; 
echo "</tr>"; 
}