hi there, for the last one week I am deliberately trying to solve my problem. Pls help me
For your better understanding, Layout of my page is something like this :

Part -A
--------
[ Dropdown list ]    [ TextBox ]
[ Table -1 ]

Part - B
--------
[ **Button** (View Selected Record) ]
[ Table -2 ]

User have to first access the dropdownlist. Based on the selection, details will be be populated in the First Table. Thereafter on clicking any row of this table. value of the first column ie the Order number will be shown in the textbox. [ Uptil here - everything is fine ]

But the problem starts from here :
When the user presses the Button value of the textbox should pass to a php variable [Which is not happening. Here the help is required]. On the basis of this variable, sql query runs which will populates the second table

Below is the code :

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <link rel="stylesheet" type="text/css" href="workstyle.css">
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script>
            function getdatafromddl(){
                var a = document.getElementById("payflag").value;
                location.href="?a="+a;
            }

            (function () {
                if (window.addEventListener) {
                    window.addEventListener('load', run, false);
                } else if (window.attachEvent) {
                    window.attachEvent('onload', run);
                }
                function run() {
                    var t = document.getElementById("show-recs");
                    t.onclick = function (event) {
                        event = event || window.event; //IE8
                        var target = event.target || event.srcElement;
                        while (target && target.nodeName != 'TR') { target = target.parentElement; }
                        var cells = target.cells; 
                        if (!cells.length || target.parentNode.nodeName == 'THEAD') {return;}
                        var f1 = document.getElementById('order_id');
                        f1.value = cells[0].innerHTML;
                    };
                }
            })();
        </script>

        <script>
            $(document).ready(function() {
                var selectedRow;
                var record;

                $('tr').click(function () {
                    $('tr').removeClass('selected');
                    $(this).addClass('selected');
                    selectedRow = $(this);
                });

                $('#viewbtn').click(function() {

                    var pickno = document.getElementById('txtOrder');

                });
            });
        </script>

    </head>
    <body>
            <div align="center">
                <img src="images/menu.jpg" alt="" />
            </div>
            <div class="centr-div">
                <!---------------------------- Row 1 [Start]-->
                <div class="f-col"> <label id="statdd">Show orders on basis of  :  </div>
                <div class="s-col">
                    <?php
                        $a = array("Paid"=>'Paid', "UnPaid"=>'Un-Paid');
                        (isset($_GET["flag"])) ? $_GET["flag"] = $a : $_GET["flag"]=null;
                    ?>
                    <select id="payflag" onchange="getdatafromddl()" class="pay">
                        <option <?php if ($a =='-1') echo ''; ?> value = "">---- Selection ----</option>
                        <option <?php if ($a == 'Paid')   echo 'selected';?> value="Paid">  Paid   </option>
                        <option <?php if ($a == 'UnPaid') echo 'selected'; ?>value="UnPaid">UnPaid</option>
                    </select>
                </div>
                <div class="l-col"><input type="text" id="order_id" name="txtOrder" /></div>
                <div class="spc"></div>
        <!-- *********************   Table - 1   ***********************  -->
                <?php
                    if (isset($_GET['a'])) {
                      $val = $_GET['a'];
                    }
                    if(!empty($val)){
                        if ($val == 'UnPaid')
                        {
                            $getrecs = "SELECT u.t_ordid, DATE_FORMAT(u.tord_dt,'%d-%m-%Y') as label_date, c.u_name, s.stat_desc  FROM utmp_orders as u join user_dtls as c on c.user_id=u.user_id join status as s on s.stat_cd=u.stat_cd WHERE u.pay_flag='N'";
                            $retrv = mysqli_query($connection, $getrecs);
                            }else if ($val == 'Paid') {
                            $getrecs = "SELECT u.t_ordid, DATE_FORMAT(u.tord_dt,'%d-%m-%Y') as label_date, c.u_name, s.stat_desc  FROM utmp_orders as u join user_dtls as c on c.user_id=u.user_id join status as s on s.stat_cd=u.stat_cd WHERE u.pay_flag='Y'";
                            $retrv = mysqli_query($connection, $getrecs);
                        }
                        else{ $retrv="";}
                    }
                ?>
                <table id='show-recs'>
                    <thead>
                        <tr>
                            <th>Order No.</th>
                            <th>Order Dt.</th>
                            <th>Client Name</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                        <?php 
                            if (!empty($retrv)){
                            while($retrvarr = mysqli_fetch_assoc($retrv)){ 
                        ?>
                            <tbody>  
                                <tr>
                                    <td><?php echo $retrvarr["t_ordid"]; ?></td>
                                    <td><?php echo $retrvarr["label_date"] ?></td>
                                    <td><?php echo $retrvarr["u_name"] ?></td>
                                    <td><?php echo $retrvarr["stat_desc"] ?></td>
                                </tr>
                            </tbody>
                        <?php }} ?>
                </table>
                <div class="spc"></div>   
                <div align="center"><input type="submit" id="viewbtn" class="showViewbtn" value="View Selected Record" /></div>
                <div class="spc"></div>
        <!-- *********************   Table - 2   *************************************************  -->
                <?php
                    $ono=null;
                    $ono = isset($_POST['txtOrder']) ? $_POST['txtOrder'] : null;
                    echo 'VAL :'.$ono;  

                    //$ono = 2;
                    if(!empty($ono)){
                        $selrec_query = "SELECT u.file_path, u.lbl_qty, u.lbl_prc, s.scat_name FROM utmp_orders as u join subcategory as s on s.scat_id = u.scat_id where u.t_ordid = {$ono}";
                        $result = mysqli_query($connection, $selrec_query);
                    }   
                ?>

                <table id='show-sel-recs'>
                        <thead>
                            <tr>
                                <th>Label Image</th>
                                <th>Qty</th>
                                <th>Price (£)</th>
                                <th>Category</th>
                                <th>Payment Recd</th>
                            </tr>
                        </thead>
                        <?php 
                            if (!empty($result)){
                                while($resultarr = mysqli_fetch_assoc($result)){ ?>
                                  <tbody>    
                                    <tr>
                                        <td><img src="<?php echo $resultarr['file_path'] ?>" alt="" style="width:61px; height:54px" /></td>
                                        <td><?php echo $resultarr["lbl_qty"] ?></td>
                                        <td><?php echo $resultarr["lbl_prc"] ?></td>
                                        <td><?php echo $resultarr["scat_name"] ?></td>
                                        <td></td>
                                    </tr>
                                  </tbody>
                            <?php 
                                }
                                if (isset($_COOKIE['sel_ordno'])){
                                    unset($_COOKIE['sel_ordno']);
                                    //setcookie("sel_ordno", "", 1);
                                    //$.cookie('sel_ordno', null);
                                }
                            } 
                            ?>
                </table>
            </div>
    </body>
</html>
<?php //get_footer(); ?>

Please help me with the code and also pls tell me where I am doing wrong?

Recommended Answers

All 2 Replies

Hello suneet,

Judging by your question, I think you might need an ajax style request built into the page. But there is another option.

You have a server / client interaction going on - php can only work on the server side, the client cannot interact directly. So, unless you want to navigate to a new page, you need to make an ajax query back to the server for the database information you are needing to lookup. That is, if you want to only push relevant information to the client.

The other option, is to load EVERYTHING into the client, then filter when they do something. This is probably much more expensive, if you have any decent size dataset.

Hello,
You Can Use Ajax for requesting data to server side and then use that data to populate your table in part-B...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.