我如何在图片上创建html表

时间:2015-11-21 06:45:21

标签: php html

我有一个3表,我正在下面的输出中进行内连接 enter image description here

我怎么能做到这样的事情 enter image description here

到目前为止,我已经有了扩展行的代码。这里真正的问题是如何获得每个tracknum的所有签名。即时通讯使用PHP和HTML

这是我的代码

                    <table  class="table table-bordered ">
                    <thead>
                      <tr>
                    <th>Track Number</th>
                    <th>Document Title</th>
                    <th>Document Type</th>
                    <th>Date Filled</th>
                    <th> </th>
                      </tr>
                    </thead>
                <?php while ($r = $q->fetch()): ?>
                        <tr>
                            <td><?php echo $r['tracknum'] ?></td>
                            <td><?php echo $r['doctitle'] ?></td>
                            <td><?php echo $r['doctype'] ?></td>
                            <td><?php echo $r['datefilled'] ?></td>
                             <td>
                             <a href="#"><span class="btnshow glyphicon glyphicon-plus-sign"></span></a>

                             </td>

                        </tr>
                        <tr><td colspan="5"><p><?php echo $r['signatoryname'] ?></p>
                        </td></tr>
                <?php endwhile; ?>

                </table> 

要扩展的表

<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$(function() {
    $("td[colspan=5]").find("p").hide();
    $("table").click(function(event) {
        event.stopPropagation();
        var $target = $(event.target);
        if ( $target.closest("td").attr("colspan") > 1 ) {
            $target.slideUp();
        } else {
            $target.closest("tr").next().find("p").slideToggle();
        }                    
    });
});
});//]]> 

</script>

这是代码的输出

enter image description here 我需要通过tracknum对下面的数据进行分组,但我需要签名 我希望html行可以扩展,并列出该跟踪的符号名称。感谢。

更新:到目前为止这是我的代码

更新:以下是正确的代码:

<?php
                require_once 'dbconfig.php';
                try {
                    $conn = new PDO("mysql:host=$host;dbname=$dbname",
                            $username, $password);
                    // execute the stored procedure
                    $sql = 'CALL sp_trasactionsignatory()';
                    $q = $conn->query($sql);
                    $q->setFetchMode(PDO::FETCH_ASSOC);
                } catch (PDOException $pe) {
                    die("Error occurred:" . $pe->getMessage());
                }
                ?>                  
                <table  class="table table-bordered ">
                    <thead>
                      <tr>
                    <th>Track Number</th>
                    <th>Document Title</th>
                    <th>Document Type</th>
                    <th>Date Filled</th>
                    <th> </th>
                      </tr>
                    </thead>
                <?php while ($r = $q->fetch()): ?>
                        <tr>
                            <td><?php echo $r['tracknum'] ?></td>
                            <td><?php echo $r['doctitle'] ?></td>
                            <td><?php echo $r['doctype'] ?></td>
                            <td><?php echo $r['datefilled'] ?></td>
                             <td>
                             <a href="#"><span class="btnshow glyphicon glyphicon-plus-sign"></span></a>

                             </td>

                        </tr>
                        <tr><td colspan="5">


                        <?php 


                        require_once 'dbconfig.php';
                        try {

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

                        $_tempp1 = $r['tracknum'];
                        $stmt = $conn->prepare("CALL sp_gettransactsignatory(?)");
                        $stmt->bindParam(1, $_tempp1, PDO::PARAM_STR, 30); 
                        $stmt->execute();
                        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
                            echo "<p>" . $row['signatoryname'] . "</p>";
                        }

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

                        ?>


                        </td></tr>
                <?php endwhile; ?>

                </table> 

1 个答案:

答案 0 :(得分:1)

<强>问题:

如何获取每个tracknum的所有签名?

<强>解决方案:

您的第一个初始查询就是这样,

(由于您未提供表名,请从以下查询中更改表名)

$q = $connection->query("SELECT tracknum, doctitle, doctype, datefilled FROM tablename GROUP BY tracknum"); 

然后来到你的桌子,

<table  class="table table-bordered ">
<thead>
<tr>
    <th>Track Number</th>
    <th>Document Title</th>
    <th>Document Type</th>
    <th>Date Filled</th>
    <th> </th>
</tr>
</thead>
<?php while ($r = $q->fetch_assoc()): ?>
    <tr>
        <td><?php echo $r['tracknum']; ?></td>
        <td><?php echo $r['doctitle'] ?></td>
        <td><?php echo $r['doctype'] ?></td>
        <td><?php echo $r['datefilled'] ?></td>
         <td>
         <a href="#"><span class="btnshow glyphicon glyphicon-plus-sign"></span></a>
         </td>

    </tr>
    <tr><td colspan="5">    
    <?php
        $result_set = $connection->query("SELECT signatoryname FROM tablename WHERE tracknum = {$r['tracknum']}");
        while ($row = $result_set->fetch_assoc()){
            echo "<p>" . $row['signatoryname'] . "</p>";
        }
    ?>
    </td></tr>
<?php endwhile; ?>

</table>

不要忘记更改两个查询中的tablename

<强>编辑:

如果您使用 PDO 扩展程序执行查询,那么您可以执行以下操作,

<?php
    $_tempp1 = $r['tracknum'];
    $stmt = $connection->prepare("SELECT signatoryname FROM tablename WHERE tracknum = :tracknum");
    $stmt->bindParam(':tracknum', $_tempp1, PDO::PARAM_STR, 30); 
    $stmt->execute();

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        echo "<p>" . $row['signatoryname'] . "</p>";
    }
?>