2017-03-08 44 views
0

我是新來的MYSQL,我想導出我的數據庫到HTML,並把數據放到特定的HTML表格。我瀏覽過網站,但我不能讓我的代碼工作,有人可以幫我,並告訴我,如果這段代碼看起來是正確的?從MYSQL導出到HTML

<?php 

    $con=mysqli_connect("xxx","xxx","xxx","xxx","xxx"); 
    // Check connection 
    if (mysqli_connect_errno()) 
    { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

    $result = mysqli_query($con,"SELECT * FROM xxx"); 

    while($row = mysqli_fetch_array($result)) 
    { 
     <tr> 
      <th bgcolor="#3281c6">" . $row["PO_nummer"]. "</th> 
      <th bgcolor="#3281c6">" . $row["Varenummer"]. "</th> 
      <th bgcolor="#3281c6">" . $row["Produkt_beskrivelse_"]. "</th> 
      <th bgcolor="#3281c6">" . $row["Antal"]. "</th> 
    } 

    mysqli_close($con); 
?> 
+0

什麼是我ssue(異常/不正確的UI渲染等),突出顯示不會強迫人們假設你的問題。 – Anil

+0

重複問題:http://stackoverflow.com/questions/17902483/show-values-from-a-mysql-database-table-inside-a-html-table-in-a-page/17902527#17902527 –

+0

這是一個好的開始寫你的HTML和PHP的報價,或外部<?php標籤。檢查如何做到這一點:http://stackoverflow.com/questions/18140270/how-to-write-html-code-inside-php – Finduilas

回答

0

你似乎在期待一個關聯數組,而不是一個常規(編號)陣列,在這種情況下可以嘗試:

while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) { // code }

0

嘗試和回聲或打印HTML

echo " 
<th bgcolor="#3281c6">" . $row["PO_nummer"]. "    </th> 
<th bgcolor="#3281c6">" . $row["Varenummer"]. "</th> 
<th bgcolor="#3281c6">" . $row["Produkt_beskrivelse_"]. "</th> 
<th bgcolor="#3281c6">" . $row["Antal"]. "</th>"; 

並在此處使用單引號bgcolor='#3281c6'