破碎的嵌套表

时间:2013-12-26 00:54:40

标签: php jquery mysql html-table

我有mysql隐藏的嵌套表。当黄色箭头单击时,嵌套表显示/隐藏。问题是我的桌子行坏了。

enter image description here

就像上面的图片一样,另一个表格行已被破坏。这有什么问题?

    <?php
        echo'<table id="tfhover" cellspacing="0" class="tablesorter">
            <thead>
            <tr>
            <th style="display:none;"></th>
            </tr>
            </thead>';
            echo'<tbody>';
        $i=1;   
    while($row = $result->fetch_assoc()){
        echo'<tr>
                <td align="center" id="none">';
                if (empty($row['qtysum'])){
                echo '<a href="javascript:void(0)"></a></td>';
                } else {
                echo '<a onclick="toggleTable(this);" data-counter="'.$rowid.'" href="#"><img src="images/arrow_right.png" border="0" width="15" height="15" title="Show List of '.$row["item_name"].'"></a></td>';
                }
                echo'<td>'.$i++.'</td>
                </tr>';

echo'<tr>';
        echo'<table id="loginTable'.$rowid.'" border="1" align="center" style="display:none">
            <thead>
            <tr>
            <th></th>
            </tr>
            </thead>';
            echo'<tbody>';
        $i=1;   
    while($row = $result1->fetch_assoc()){
        echo'<tr>
            <td>'.$i++.'</td>
            </tr>';
           }
    echo "</tbody></table></tr>";
           }
          }
        echo "</tbody></table>";
    ?>

这是我的show / hide table脚本。

<script>
function toggleTable(link) {
     var elem=document.getElementById("loginTable" + link.getAttribute('data-counter'));
     var hide = elem.style.display =="none";
     if (hide) {
        elem.style.display="table";
     } else {
        elem.style.display="none";
     }
     return false;
 }
</script>

如果有<tr><td> </td></tr>

1 个答案:

答案 0 :(得分:0)

看起来在创建子表之前没有打开父td,并且还缺少结束标记。

使用<!-- -->

评论进行更改的部分
    <?php
        echo'<table id="tfhover" cellspacing="0" class="tablesorter">
            <thead>
            <tr>
            <th style="display:none;"></th>
            </tr>
            </thead>';
            echo'<tbody>';
        $i=1;   
    while($row = $result->fetch_assoc()){
        echo'<tr>
                <td align="center" id="none">';
                if (empty($row['qtysum'])){
                echo '<a href="javascript:void(0)"></a></td>';
                } else {
                echo '<a onclick="toggleTable(this);" data-counter="'.$rowid.'" href="#"><img src="images/arrow_right.png" border="0" width="15" height="15" title="Show List of '.$row["item_name"].'"></a></td>';
                }
                echo'<td>'.$i++.'</td>
                </tr>';

echo'<tr><td>'; <!-- there was no td opened here -->
        echo'<table id="loginTable'.$rowid.'" border="1" align="center" style="display:none">
            <thead>
            <tr>
            <th></th>
            </tr>
            </thead>';
            echo'<tbody>';
        $i=1;   
    while($row = $result1->fetch_assoc()){
        echo'<tr>
            <td>'.$i++.'</td>
            </tr>';
           }
        echo "</tbody></table>";
    <!-- opened tr,td are closed here -->
        echo "</td></tr>"
           }
          }
        echo "</tbody></table>";
    ?>