php - 在 php mysql while 循环上运行 jquery 函数

标签 php jquery mysql css

主要目的是点击主行时显示行,一个事件id会有多个记录。如何为这种类型的输出应用 jquery 函数。帮助表示赞赏。

我尝试使用 jexpand 函数,但它不起作用。

主要目的是获得类似的输出,当单击一个特定行时,应展开具有相同 ID 的剩余行集,反之亦然。

表结果是从mysql数据库中获取的。

<html>
    <head>
    <meta charset="UTF-8">
    <style type="text/css">
            body { font-family:Arial, Helvetica, Sans-Serif; font-size:0.8em;}
            #report { border-collapse:collapse;}
            #report h4 { margin:0px; padding:0px;}
            #report img { float:right;}
            #report ul { margin:10px 0 10px 40px; padding:0px;}
            #report th { background:#7CB8E2 url(header_bkg.png) repeat-x scroll center left; color:#fff; padding:7px 15px; text-align:left;}
            #childALL { background:#C7DDEE none repeat-x scroll center left; color:#000; padding:7px 15px; }
            #report tr.td { background:#fff url(row_bkg.png) repeat-x scroll center left; cursor:pointer; }
            #report div.arrow { background:transparent url(arrows.png) no-repeat scroll 0px -16px; width:16px; height:16px; display:block;}
            #report div.up { background-position:0px 0px;}
        </style>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">  
            $(document).ready(function(){
                $("#report tr:siblings").show();
                $("#report tr:siblings").hide();
                $("#report div.arrow").click(function(){
                    $(this).next("#childALL").toggle();
                    $(this).find(".arrow").toggleClass("up");
                });
                //$("#report").jExpand();
            });
        </script>
    </head>
<body>
    <center>
        <img src="abc.jpg" width="400px" height="100px" />
    </center>

    <?php
        $con=  mysqli_connect("172.28.212.145", "root", "root", "xxx");

        if(!$con)
        {
            die('not connected');
        }

        $con=  mysqli_query($con, "Select Incident_id,name,qualification from masterdata;");
       ?>
    <div>
        <center>
            <table id="report">
                <tr>
                    <th>Incident Id</th>
                    <th>name</th>
                    <th>Qualification</th>
                    <th></th>
                </tr>
                <?php
                $incident = null;
                while($row = mysqli_fetch_array($con))
                {
                    if( $row['Incident_id'] != $incident )
                    {   
                        $incident = $row['Incident_id'];
                ?>
                <tr>
                    <td>
                        <?php echo $row['Incident_id']; ?>
                    </td>
                    <td>
                        <?php echo $row['name']; ?>
                    </td>
                    <td>
                        <?php echo $row['JournalUdpdateChanges']; ?>
                    </td>
                    <td><div class="arrow"></div></td>
                </tr>

                <?php } else { ?>

                <tr id="childALL">
                    <td >
                        <?php echo $row['Incident_id']; ?>
                    </td>
                    <td >
                        <?php echo $row['name']; ?>
                    </td>
                    <td >
                        <?php echo $row['qualification']; ?>
                    </td>
                    <td >
                        <?php echo $row['Priority_im']; ?>
                    </td>
                </tr> 
                <?php
                    }
                }
                ?>
            </table>
        </center>
    </div>
</body>
</html>

最佳答案

Bootstrap 使这方面的工作变得非常容易。

Bootstrap Accordion

关于php - 在 php mysql while 循环上运行 jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35858547/

相关文章:

php - 如何在 php 中复制唯一的特定扩展文件?

php - 将 CI 查询存储到数组中?

javascript - symfony2 中的单 Ajax

php - 如何在 PHP 中将数据库 URL 显示为网页 URL

php - 如何将答案存储到 MySQL 表

PHP搜索结果分页

Centos 中的 PHP Codeigniter : include_once failing for custom system libraries

php - 如何使用 PHP 构建基于 Web 的电子邮件客户端?

javascript - 使用 jquery 选择单个下一个兄弟

javascript - 将 div 元素从一个父 div 移动到另一个