如何在同一页面显示输入和输出?

时间:2015-03-11 09:38:49

标签: javascript php jquery mysql

我只有一个PHP文件。但使用两个单独的PHP标记。如果我单击第一个PHP标记表中的第一行,我需要在同一页面的第二个PHP标记的表中显示第一行值。两个表的公共字段是order_id 输出应显示在第一个表的旁边。

<head>               
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>

<script type="text/javascript">
$(function() {
$('.one').click(function() {
$(".slidediv").slideToggle();
});

});
</script>
</head>
<body>
<?php
            session_start();
            include "db.php";
            $query = "select * from orders_list";
            $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'>
                 <tr class='tr_class' bgcolor='#0066CC'>
                 <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'> no_of_pack </td>
                 <td align='center' style='font-weight:bold'> price </td>
                 <td align='center' style='font-weight:bold'> Weight </td>
                 <td align='center' style='font-weight:bold'> payment mode </td>



            </tr>";

                while($row = mysql_fetch_array($result))

                {


                        echo "<tr class='one' data-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['number_of_pack']."</td>
                        <td align='center'>".$row['price']."</td>
                        <td align='center'>".$row['weight']."</td>
                        <td align='center'>".$row['payment']."</td>";


                        /*echo "<td align='center'><a href='pin.php?increment_id=".$row['increment_id']."&postcode=".$row['postcode']."&proposed_shipping=".$proposed_shipping." '>SUBMIT</a></td>";*/

                echo "</tr>";
                        }
                        $order_id = $row['order_id'];
                        global $order_id;
                        echo "</table>";
                        echo "</div>";
                        }


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

            ?>

            <div>
            <?php

            include "db.php";

            global $order_id;
            $query = "select * from orders_details where order_id=$order_id";
            echo $query;
            $result = mysql_query($query);

            $num_rows = mysql_num_rows($result);
            if($num_rows >= 1)
                {
                echo "<div class='menu' class='scroll'>";   
            echo "<table id='table_struct' cellspacing='0' cellpadding='1' border='1' width='400'>
                 <tr class='slidediv' bgcolor='#0066CC'>
                 <td align='center' style='font-weight:bold'> Product </td>
                 <td align='center' style='font-weight:bold'> Quantity </td>
                 <td align='center' style='font-weight:bold'> Sku </td>
                 <td align='center' style='font-weight:bold'> Price </td>
                 <td align='center' style='font-weight:bold'> Total </td>

            </tr>";

                while($row = mysql_fetch_array($result))
                {
                        echo "<tr class='slidediv'>
                        <td align='center'><input type='checkbox' class='case' name='case' value='1'></td>
                        <td align='center'>".$row['product']."</td>
                        <td align='center'>".$row['quantity']."</td>
                        <td align='center'>".$row['sku']."</td>
                        <td align='center'>".$row['price']."</td>
                        <td align='center'>".$row['total']."</td>";

                echo "</tr>";
                        }
                        echo "</table>";
                        echo "</div>";
                        }
        if(!mysql_close($con))
        {
            echo "failed to close";
        }   
            ?>
</body>

1 个答案:

答案 0 :(得分:0)

无需声明$ order_id全局,只需输入您的代码$ order_id = $ row ['order_id'];在while循环中,在你的页面中随处使用它并享受..