0

I am trying to fetch data on change of date using date type,have fetched data from database. But after that, the data that is fetched contains button to be clicked. On click of button fetch the data again.

Here is the code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>

</head>
<body>
    <form method="post">
        <input type="date" name="gdate" id="gdate" onchange="<?php echo $_SERVER['PHP_SELF'] ?>"/>
    </form>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>
        function makeAjaxRequest(dateval) {
            $.ajax({
                type: "GET",
                data: {dateva: dateval},
                url: "fetchbills.php",
                success: function (data) {
                    $('#showresult').html(data);
                    $('#det').on("click", function () {
                        var no = $(this).val();
                        makeAjaxRequest2(no);
                    });
                }
            });
        }
        function makeAjaxRequest2(billno) {
            $.ajax({
                type: "GET",
                data: {bno: billno},
                url: "fetchbilldetail.php",
                success: function (data) {
                    $('#showresult').html(data);
                }
            });
        }
        $("#gdate").on("change", function () {
            var id = $(this).val();
            makeAjaxRequest(id);

        });
    </script>
    <div id="showresult">

    </div>
</body>
</html>

fetchbills.php

<?php

include("./config.php");
$dt = $_REQUEST["dateva"];
$sql = "select bill_id,order_id from bill_master where order_date='$dt'";
echo $sql;
$result = mysqli_query($con, $sql) or die("error");
if ($result) {
    while ($row = mysqli_fetch_array($result)) {
        echo $row[0] . "<br>";
        echo "<form method='post' action=''><input type='submit' name='det' value='" . $row[1] . "' onclick='get(this.value)' /></form>
    <div id='show'></div>";
    }
}
?>

using the above I get order id.The id's are displayed in form of buttons. On click of buttons I want to get the details of order id.but what sholud I do I can't understand.

I am new to ajax and don,t know how to do it.

here the the code for order details

<?php

include("./config.php");
$det = $_GET["bno"];
//echo $det;
$sql = "SELECT m.old_order_id,m.old_order_amount,l.item_id,l.old_order_quantity,i.item_name from old_order_master m,old_order_list l,item_list i where m.old_order_id=$det and m.old_order_id=l.old_order_id and l.item_id=i.item_id";
//echo $sql;
$result = mysqli_query($con, $sql);
echo "<table><tr><th>Item Name</th><th>Quantity</th></tr>";
while ($row = mysqli_fetch_array($result)) {

    echo "<tr><td>" . $row[4] . "</td><td>" . $row[3] . "</td></tr>";
}
echo "</table>";
?>
4
  • You got any error message? Commented Aug 2, 2016 at 17:17
  • no error but I didn't get the another data i.e order details on button click. Commented Aug 2, 2016 at 17:34
  • Can anyone please give suggestion,have to complete it as soon as possible. Commented Aug 2, 2016 at 17:44
  • Use type post in ajax Commented Aug 2, 2016 at 17:51

1 Answer 1

1

Make following changes in your fetchbills.php file and let me know

<?php

include("./config.php");

$dt = $_REQUEST["dateva"];
$sql = "select bill_id,order_id from bill_master where order_date='$dt'";

$result = mysqli_query($con, $sql) or die("error");

if ($result) {
    while ($row = mysqli_fetch_array($result)) {

        echo $row[0] . "<br>";
        echo "<form method='post' action=''>"
            ."<input type='button' name='det' value='" . $row[1] . "' onclick='makeAjaxRequest2(".$row[1].");' /></form>"
            ."<div id='show'></div>";
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

hey the data is outputed,but it disappers within a blink and the html page i.e the 1 page with date picker without any value is reloaded back.without anything.
Are you sure you've used above entire code for fetchtbills.php? For page not to refresh I've added type="button" instead of type="submit"
sorry missed that thing.thanks a lot for your help. Its working. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.