表格里面的PHP错误输出

时间:2016-03-03 16:21:41

标签: php html

我有一个HTML表格,数据来自数据库。然后,我又添加了第二张表。

单击该行可显示该表。该行已展开并显示第二个表。

我的代码出了什么问题?它从数据库中提供数据,但它不会循环。例如,我期待3行,但它只输出一行。

查询是正确的。

这是第二个表的代码,

<table class="table">
    <thead>
    <tr>
        <th>Name</th>
        <th>Date filled</th>
        <th>Date signed</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <?php 


    require_once 'dbconfig.php';
    try {

    $conn = new PDO("mysql:host=$host;dbname=$dbname",
        $username, $password);

    $_tempp1 = $row1['tracknum'];
    $stmt = $conn->prepare("CALL sp_gettransactsignatory(?)");
        $stmt->bindParam(1, $_tempp1, PDO::PARAM_STR, 30);
        $stmt->execute();


        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>

    <tr>
        <td><?php echo $row['signatoryname'] ?></td>
        <td><?php echo $row['datefilled'] ?></td>
        <td><?php echo $row['datesigned'] ?></td>

    </tr>


    <?php
    }



    } catch (PDOException $pe) {
    die("Error occurred:" . $pe->getMessage());
    }

    ?>
    </tr>

    </tbody>
</table>

</td>
</tr>

1 个答案:

答案 0 :(得分:3)

评论的变化: -

  <tr>
        <td colspan="5">

            <table class="table">
            <thead>
              <tr>
                <th>Name</th>
                <th>Date filled</th>
                <th>Date signed</th>
              </tr>
            </thead>
            <tbody>
              <!-- remove <tr> -->
            <?php 
            require_once 'dbconfig.php';
            try {   
                $conn = new PDO("mysql:host=$host;dbname=$dbname",
                $username, $password);

                $_tempp1 = $row1['tracknum'];
                $stmt = $conn->prepare("CALL sp_gettransactsignatory(?)");
                $stmt->bindParam(1, $_tempp1, PDO::PARAM_STR, 30); 
                $stmt->execute();
                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>
                  <tr>
                    <td><?php echo $row['signatoryname']; ?></td><!-- ; missed -->
                    <td><?php echo $row['datefilled']; ?></td><!-- ; missed -->
                    <td><?php echo $row['datesigned']; ?></td><!-- ; missed -->
                 </tr>
            <?php}} catch (PDOException $pe) {
                die("Error occurred:" . $pe->getMessage());
            }?> 
            <!-- remove </tr> -->
            </tbody>
            </table>
        </td>
    </tr>