如何使用ajax隐藏上一行

时间:2015-03-16 07:00:18

标签: php ajax

当我点击左表的第一行时,右侧输出。当我点击第一个表的第二行时,第二行输出应该只到第一行输出和第二行输出都显示第一行输出没有得到隐藏。

你能帮助我解决这个问题。

php代码:

           <?php
                        session_start();
                        include "db.php";
                        $query = "select * from purna_orders";
                        $result = mysql_query($query);

                        $num_rows = mysql_num_rows($result);
                        if($num_rows >= 1)
                            {

                            echo "<div id='showmenu' class='scroll'>";  
                        echo "<table id='table_struct' cellspacing='0' cellpadding='1' border='1' width='400' height='30'>
                             <tr class='tr_class' bgcolor='white'>
                             <td align='center' style='font-weight:bold'> Select </td>
                             <td align='center' style='font-weight:bold'> order_id </td>
                             <td align='center' style='font-weight:bold'> customer_name </td>

                             <td align='center' style='font-weight:bold'> price </td>

                             <td align='center' style='font-weight:bold'> payment mode </td>



                        </tr>";

                            while($row = mysql_fetch_array($result))
                            {

                                    $order_id = $row['order_id'];
                                    $_SESSION['order_id'] = $order_id;
                                    echo "<tr height='20' data-order_id='".$row['order_id']."'>
                                    <td align='center'><input type='checkbox' class='case' name='case' value='1'></td>
                                    <td align='center'>".$row['order_id']."</td>
                                    <td align='center'>".$row['customer_name']."</td>

                                    <td align='center'>".$row['order_value']."</td>

                                    <td align='center'>".$row['bill_to_pincode']."</td>";

                            echo "</tr>";
                                    }
                                    echo "</table>";
                                    echo "</div>";
                                    }


                    if(!mysql_close($con))
                    {
                        echo "failed to close";
                    }   

                        ?>

Ajax代码:

<script type="text/javascript">
    $('#table_struct tr').click(function() {
        var $this = $(this);
        var offset = $this.offset();
        var height = $this.height();
        var order_id = $this.data('order_id');
        $.get('getuser.php?order_id=' + order_id, function(table) {
            $('.menu').append(table);
            $('.menu').css({
                right: offset.right,
                top: offset.top+height
            });
        });
    });
</script>

getuser.php

              <?php
              include "db.php";
              $order_id = intval($_GET['order_id']);

               $sql="SELECT * FROM purna_order_items WHERE order_id = '".$order_id."'";
               $result = mysql_query($sql);
               echo "<div style=margin-top:-398px; margin-bottom:0px;'>";
               echo "<table border='1' style='background-color:white; font-style:bold;'>
               <tr>
               <td align='center'><b>Increment Id</b></td>
               <td align='center'><b>Po Order Id</b></td>
               <td align='center'><b>Item Sku</b></td>
               <td align='center'><b>Item Name</b></td>
               <td align='center'><b>Item Price</b></td>
               <td align='center'><b>Item Quantity</b></td>
               <td align='center'><b>Item Weight</b></td>
               </tr>";
               while($row = mysql_fetch_array($result)) {
               echo "<tr>";
               echo "<td align='center'>" . $row['order_id'] . "</td>";
               echo "<td align='center'>" . $row['po_id'] . "</td>";
               echo "<td align='center'>" . $row['sku'] . "</td>";
               echo "<td align='center'>" . $row['item_name'] . "</td>";
               echo "<td align='center'>" . $row['item_price'] . "</td>";
               echo "<td align='center'>" . $row['item_qunatity'] . "</td>";
               echo "<td align='center'>" . $row['weight'] . "</td>";
               echo "</tr>";
               }
               echo "</table>";
               echo "</div>";
               mysql_close($con);
               ?>

输出截图:

enter image description here

1 个答案:

答案 0 :(得分:0)

您的代码没有足够的信息,但尝试使用此代码,如果它有帮助 -

<script type="text/javascript">
    $('#table_struct tr').click(function() {
        var $this = $(this);
        var offset = $this.offset();
        var height = $this.height();
        var order_id = $this.data('order_id');
        $.get('getuser.php?order_id=' + order_id, function(table) {
            $('.menu', $this).append(table);
            $('.menu', $this).css({
                right: offset.right,
                top: offset.top+height
            });
        });
    });
</script>