2016-01-20 40 views
1

我想從mySQL數據庫中獲取數據並將它們放入HTML表格中。在互聯網上搜索了很多東西之後,我卻沒有找到適合我的代碼。將SQL數據放入HTML表格。表頭重複

目前,我有這樣的代碼

**<?php 
error_reporting(E_ALL^E_DEPRECATED); 
$user = "root"; 
$password = ""; 

$db = mysql_connect('localhost', $user, $password); 

if (!$db) { 
    die('Not connected : ' . mysql_error()); 
} 

$dbname = "btcx2"; 

      $db_select = mysql_select_db($dbname,$db); 
      if (!$db_select) { 
       die("Database selection also failed miserably: " . mysql_error()); 
      } 

      $results = mysql_query("SELECT btcaddress, btclink, btcreceived , btctarnsaction, lastdeposit, reg_date, uptodate , btcdoubble FROM btctrans"); 
      while($row = mysql_fetch_array($results)) { 

      ?> 
    <table style="width:95%;height:95%;" border="2"> 
    <thead> 
     <tr> 
      <th><strong>Date</strong></th> 
      <th><strong>BTC Address</strong></th> 
      <th><strong>Amount Deposited</strong></th> 
      <th><strong>Amount Returned</strong></th> 
      <th><strong>Transaction</strong></th> 
     </tr> 
    </thead> 
    <tbody>  

    <tr> 
       [<td><font color="red"> <?php echo $row\['reg_date'\]?></font></td> 
       <td> <a href="<?php echo $row\['btclink'\]?>"><?php echo $row\['btcaddress'\]?></a></td> 
       <td><font color="red">BTC: <?php echo $row\['btcreceived'\]?> </font></td> 
       <td><font color="red">BTC: <?php echo $row\['btcdoubble'\]?></font></td> 
       <td><font color="red"> <?php echo $row\['btctarnsaction'\]?></font></td>][1] 

      </tr> 

      <?php 
     } 
     ?> 


     </tbody> 
     </table></center>** 

每當插入數據時,表頭,重複與表中的數據。我使用「mysql_connect」而不是「mysqli」。請解決這個問題,幫助我解決這個問題。

這裏是錯誤的圖片: - http://i.stack.imgur.com/1yOZ3.png

回答

4

你需要把表頭

你的頭被重複,每一個記錄之前(退出循環)。

應該只來一次。

更正代碼:

<table style="width:95%;height:95%;" border="2"> 
<thead> 
<tr> 
    <th><strong>Date</strong></th> 
    <th><strong>BTC Address</strong></th> 
    <th><strong>Amount Deposited</strong></th> 
    <th><strong>Amount Returned</strong></th> 
    <th><strong>Transaction</strong></th> 
</tr> 
</thead> 
<?php 
while($row = mysql_fetch_array($results)) { 
?> 
+0

謝謝。有效 !! –