0

i have been rearrange the code for whole day still cannt make the datepicker search filter working only the dropdown select filter is working.. previously is datepicker search filter is working and dropdown options is not working, but i working it and it turns around where the datepicker is not working but the dropdown search is working.. give me a hints for this. When select the date range it does not fetch any data and the table display empty.

2
Contributors
2
Replies
22
Views
1 Year
Discussion Span
Last Post by diafol
0

[code]

            <?php

            include '../include/navbar.php';
                $post_at = "";
                $post_at_to_date = "";
                $count = 1000;

                $queryCondition = "";
                if(!empty($_POST["search"]["DOCDATE"])) {            
                    $post_at = $_POST["search"]["DOCDATE"];
                    list($fid,$fim,$fiy) = explode("-",$post_at);

                    $post_at_todate = date('Y-m-d');
                    if(!empty($_POST["search"]["post_at_to_date"])) {
                        $post_at_to_date = $_POST["search"]["post_at_to_date"];
                        list($tid,$tim,$tiy) = explode("-",$_POST["search"]["post_at_to_date"]);
                        $post_at_todate = "$tiy-$tim-$tid";
                    }

                    $queryCondition .= "WHERE sl_iv.DOCDATE BETWEEN '$fiy-$fim-$fid' AND '" . $post_at_todate . "'";
                }

                $sql = "SELECT * From `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id " . $queryCondition . " ORDER BY sl_iv.DOCNO Asc";
                $result = mysqli_query($conn_connection,$sql);

                $item_q = "SELECT * FROM `sl_iv`";
                $item = mysqli_query($conn_connection, $item_q);

                $curdate = "SELECT DATEDIFF(CURDATE(), `DOCDATE`) AS DAYS FROM ar_iv";
                $resultdate = mysqli_query($conn_connection, $curdate);

            ?>

            </head>
            <body class="invoice" onLoad="calculateSum()">
            <div class="modal-body">    
                <div id="page-wrap">
                        <textarea id="header">Report</textarea>

                    <div id="cust">

                        <textarea id="cust-title"></textarea>

                        <table id="meta">
                            <tr>
                                <td class="meta-head">Report No.</td>
                            <td name="reportno" class="input-control" /><?php echo $count; ?></td>

                            </tr>
                            <tr>

                                <td class="meta-head">Date</td>
                                <td placeholder="Today Date" name="todaydate" class="input-control" /><?php echo date('Y-m-d'); ?></td>
                            </tr>

                        </table>

                    </div>        
                    <br></br>

                    <form name="frmSearch" id="frmSearch" method="post" action="cust_due_test.php">
                        <input type="text" placeholder="From Date" id="post_at" name="search[DOCDATE]"  value="<?php echo $post_at; ?>" class="input-control" />
                        <input type="text" placeholder="To Date" id="post_at_to_date" name="search[post_at_to_date]" style="margin-left:10px"  value="<?php echo $post_at_to_date; ?>" class="input-control"  />    

                        <select name= "COMPANYNAME">
                        <option value="">ALL</option>

                        <?php
                            $query = mysqli_query($conn_connection, "SELECT * FROM sl_iv GROUP by COMPANYNAME");

                            while ($row = mysqli_fetch_assoc($query)) {
                            echo "<option value='".$row["COMPANYNAME"]."'".($row["COMPANYNAME"]==$_POST["COMPANYNAME"] ? " selected" : "").">".$row["COMPANYNAME"]."</option>";
                        }
                        ?>
                        </select>
                        <input type="submit" name="submit" id="button "value="Submit"/>
                        <a href="cust_due_test.php">reset</a>
                <br></br>

                    <table id="items">
                        <center>
                        <thead>
                            <tr>
                                <th width="15%" style="text-align:center"><span>Doc No.</span></th>
                                <th width="10%" style="text-align:center"><span>Date</span></th>
                                <th width="10%" style="text-align:center"><span>Terms</span></th>
                                <th width="10%" style="text-align:center"><span>Due</span></th>
                                <th width="5%" style="text-align:center"><span>Age</span></th>
                                <th width="20%" style="text-align:center"><span>Customer Name</span></th>
                                <th width="10%" style="text-align:center"><span>Ammount</span></th>
                                <th width="10%" style="text-align:center"><span>Payment</span></th>
                                <th width="10%" style="text-align:center"><span>OutStanding</span></th>
                            </tr>
                        </thead>
                        </center>

                        <tbody>
                        <?php
                        if(isset($_POST['COMPANYNAME']))
                    {
                        $COMPANYNAME = $_POST['COMPANYNAME'];
                        $fetch = "SELECT * FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE COMPANYNAME = '".$COMPANYNAME."'";
                        $result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
                    }
                        if (mysqli_num_rows($result) > 0) {
                            // output data of each row
                            while($row = mysqli_fetch_assoc($result)) {

                            $docamt = $row['DOCAMT']; 
                            $paymentamt = $row['PAYMENTAMT'];
                            $outstanding = $docamt - $paymentamt;

                            $then = $row['DOCDATE'];
                            $then = strtotime($then);

                            $now = time();

                            $difference = $now - $then;
                            $dateage = floor($difference / (60*60*24));
                        ?>                
                        <tr class="item-row">
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm DocNo" id=DocNo0" name="DocNo[]" value="<?php echo htmlspecialchars($row['DOCNO']);?>" readonly></td>
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm DocDate" id="DocDate0" name="DocDate[]" value="<?php echo htmlspecialchars($row['DOCDATE']);?>" readonly></td>
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm Terms" id="Terms0" name="Terms[]" value="<?php echo htmlspecialchars($row['terms']);?>" readonly></td>
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm DueDate" id="DueDate0" name="DueDate[]" value="<?php echo htmlspecialchars($row['DUEDATE']);?>" readonly></td>
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm DateAge" id="DateAge0" name="DateAge[]" value="<?php echo $dateage;?>" readonly></td>
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm CompanyName" id="CompanyName0" name="CompanyName[]" value="<?php echo htmlspecialchars($row['COMPANYNAME']);?>" readonly></td>
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm TotalAmt" id="TotalAmt0" name="TotalAmt[]" value="<?php echo htmlspecialchars($row['DOCAMT']);?>" readonly></td>
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm payment" id="payment0" name="payment[]" value="<?php echo htmlspecialchars($row['PAYMENTAMT']);?>" readonly></td>
                            <td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm Total_Outstanding" id="Total_Outstanding0" name="Total_Outstanding[]" value="<?php echo number_format((float)$outstanding, 2, '.', '');?>" readonly></td>
                        </tr>
                        <?php
                            }
                        } else {
                            echo "0 results";
                        }
                        ?>

                        </tbody>
                    </table>
                </form>   
            </div>
            </div>

[/code]

Edited by Test_2

0

i have been rearrange the code for whole day still cannt make the datepicker search filter working only the dropdown select filter is working.. previously is datepicker search filter is working and dropdown options is not working, but i working it and it turns around where the datepicker is not working but the dropdown search is working..

I'm afraid that sounds so convoluted. In simple terms are you saying that the dropdown filter is working but the datpicker filter isn't?

If you are requesting info from the DB, then a GET request should be used. If the request is changing DB data, then use post. There are exceptions, such as logins however.

Your form should be changed to GET and simplifying your form fields should help. Also not sure why the result section is inside your form.

You are sending the form to cust_due_test.php - is this the same page as the form or is it different? If different, then no POST vars will be passed back to the form as it has to make a trip to the form handling page first. In assuming the first scenario.

I'd probably approach it like this:

<?php
    require "db.php";
    require "companies.php";

    $srcDateFrom = ( isset($_GET['src-date-from'] ) && $_GET['src-date-from'] ) ? $_GET['src-date-from'] : '';
    $srcDateTo = ( isset($_GET['src-date-to'] ) && $_GET['src-date-to'] ) ? $_GET['src-date-to'] : '';
    $srcSelCompany = ( isset($_GET['src-company'] ) ) ? $_GET['src-company'] : '';
    $srcCompanyList = '<option>ALL</option>' . getCompanies( $srcSelCompany ); //function in companies.php to get <option>
    $resultsTable = getResultsTable(); //function to get table of results in companies.php
?>

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Page Title</title>
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="stylesheet" href="">
</head>
<body>

    <form method="get" action="" class="form-inline">
        <div class="form-group">
            <label for="src-date-from">Date from</label>
            <input type="date" class="form-control" name="src-date-from" id="src-date-from" value="<?=$srcDateFrom?>">
        </div>
        <div class="form-group">
            <label for="src-date-to">Date to</label>
            <input type="date" class="form-control" name="src-date-to" id="src-date-to" value="<?=$srcDateTo?>">
        </div>
        <div class="form-group">
            <label for="src-company">Company</label>
            <select class="form-control" id="src-company" name="src-company">
                <?=$srcCompanyList?>
            </select>
        </div>
        <button type="submit" class="btn btn-default">Search</button>
    </form>

    <div>
        <h3>Search Parameters:</h3>
        <p>Date from: <?=$srcDateFrom?></p>
        <p>Date to: <?=$srcDateTo?></p>
        <p>Company: <?=$srcSelCompany?></p>
    </div>
    <div>
        <h3>Search Results</h3>
        <?=$resultsTable?>
    </div>
</body>
</html>

Hide away the php code in functions in the include file - no need to contaminate your HTML with it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.