【问题标题】:how do i create html table like on the picture我如何在图片上创建 html 表格
【发布时间】:2015-11-21 06:45:21
【问题描述】:

我有一个 3 表,我在下面的输出中进行内部连接

我怎样才能达到这样的目的

到目前为止,我已经有了扩展行的代码。这里真正的问题是我如何获得每个 tracknum 的所有 signatoryname。我使用 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>

这是代码的输出

我需要按tracknum对下面的数据进行分组,但我需要signatoryname 我希望 html 行是可扩展的,并在下面列出该 tracknum 的签名名称。谢谢。

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

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

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

【问题讨论】:

  • 能贴出代码吗?
  • 这可能对你有帮助:stackoverflow.com/questions/16926752/…
  • 以上帖子已更新,先生。用代码
  • @nickdbush sir 用于扩展表格的行。我已经有代码了。我的问题是我如何对数据进行分组但不抛出其他签名者姓名。我在mysql上试过但找不到解决办法

标签: php html


【解决方案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>";
    }
?>

【讨论】:

  • 先生,我更新了上面的代码。现在的问题是它只检索第二行的签名者姓名。但不在 html 表的第一行。我的意思是查询不适用于表的第一行。但适用于第二个。对不起我的英语不好
  • 为什么是CALL sp_gettransactsignatory(?)?对存储过程有什么特殊需求吗?因为一个简单的查询会给你所需的结果。
  • 我使用存储过程先生来减少代码并且更容易更改 sql。我试过代码先生,但它仍然是一样的。我什至回显了 $r['tracknum'];检查tracknum是否正确。但我不明白。为什么即使tracknum正确也不查询第一行
  • 我已经在我的系统上测试了你的代码,它的工作方式和你期望的一样(包括 javascript 代码)。在你的机器上运行this tested code。如果您仍想使用sp_gettransactsignatory(?) 存储过程,请确保其中的所有内容都正确。
  • 我在 mysql 先生上测试了 sp_gettransactsignatory。所以我知道它是正确的,如果它错误,它将无法正确查询第二行。我试试你是代码先生,我会试着找出我的问题,谢谢
猜你喜欢
  • 1970-01-01
  • 2021-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
  • 1970-01-01
相关资源
最近更新 更多