dq13733519262 2016-01-20 07:34 采纳率: 0%
浏览 89
已采纳

将SQL数据放入HTML表。 表头是重复的

I'm trying to get the data from my mySQL database and put them into a HTML table. After searching a lot on the internet, but I coudn't find code that worked for me.

Currently, I have this code

**<?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>**

Every time when the data is inserted, table headers are repeated with the table data . i used "mysql_connect" and not "mysqli" . please some one fix this help me on this problem.

here is a picture of the error : - http://i.stack.imgur.com/1yOZ3.png

  • 写回答

1条回答 默认 最新

  • douzheng9221 2016-01-20 07:36
    关注

    You need to put table headers before (out of loop)

    Your headers are repeating for every record.

    The should come only once.

    Corrected code:

    <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)) {
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站