selvam1985 Posted April 19, 2022 Share Posted April 19, 2022 MAIN.PHP <html> <form name="input"> <input type="date" id="userdate"> <input type="text" size="50" id="searchterm"> </form> <div id="content"></div> </html><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" /> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"> </script> <script> $(document).ready(function () { $('#searchterm').change(function() { userdate = $("#userdate").val(); searchterm = $("#searchterm").val(); $.ajax({ type:'GET', url: 'test2.php', data: {userdate:userdate,searchterm :searchterm}, dataType: "json", async: false, success: function(data) { alert(data); document.getElementById('#content').innerHTML += value; $("#content").html(data); //console.log(data); } }); }); }); </script> TEST2.PHP <?php include('/include/config1.php'); $kdt = $_GET['userdate']; $searchTerm = $_GET['searchterm']; $select =mysql_query("SELECT man_id,man_name,join_date FROM manmaster where (man_id LIKE '%".$searchTerm."%' or man_name LIKE '%".$searchTerm."%') and join_date<='$kdt' ") or die('Query not Executed..!..' .mysql_error()); while ($row=mysql_fetch_array($select)) { $data[] = $row['join_date']."-".$row['man_id']."-".trim($row['man_name']); //$data[] = $row['eff_date']."-".$row['token_id']."-".$row['man_id']."-".trim($row['man_name']); //$data[] = $row['token_id']."-".$row['man_id']."-".trim($row['man_name'])."-(".$row['eff_date'].")"; } echo json_encode($data); ?> THE FOLLOWING AUTOSEARCH CODE WORKING FINE...but here i didnot know how to pass the date value then the employee id or Employee name value <script> //type="text/javascript"> $(function() { $( "#searchterm" ).autocomplete({ //source:"autosearchwithdate.php?effdate="+$('#effdate').val()+"&"+"empsearch="+$('#empsearch').val(), source: 'autocomplete_salary.php' //source: 'autosearchwithdate.php' }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/314715-parameter-passing-in-the-autosearch-without-ajax-or-with-ajax/ Share on other sites More sharing options...
selvam1985 Posted April 19, 2022 Author Share Posted April 19, 2022 (edited) 30 minutes ago, selvam1985 said: MAIN.PHP <html> <form name="input"> <input type="date" id="userdate"> <input type="text" size="50" id="searchterm"> </form> <div id="content"></div> </html><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" /> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"> </script> <script> $(document).ready(function () { $('#searchterm').change(function() { userdate = $("#userdate").val(); searchterm = $("#searchterm").val(); $.ajax({ type:'GET', url: 'test2.php', data: {userdate:userdate,searchterm :searchterm}, dataType: "json", async: false, success: function(data) { alert(data); document.getElementById('#content').innerHTML += value; $("#content").html(data); //console.log(data); } }); }); }); </script> TEST2.PHP <?php include('/include/config1.php'); $kdt = $_GET['userdate']; $searchTerm = $_GET['searchterm']; $select =mysql_query("SELECT man_id,man_name,join_date FROM manmaster where (man_id LIKE '%".$searchTerm."%' or man_name LIKE '%".$searchTerm."%') and join_date<='$kdt' ") or die('Query not Executed..!..' .mysql_error()); while ($row=mysql_fetch_array($select)) { $data[] = $row['join_date']."-".$row['man_id']."-".trim($row['man_name']); //$data[] = $row['eff_date']."-".$row['token_id']."-".$row['man_id']."-".trim($row['man_name']); //$data[] = $row['token_id']."-".$row['man_id']."-".trim($row['man_name'])."-(".$row['eff_date'].")"; } echo json_encode($data); ?> THE FOLLOWING AUTOSEARCH CODE WORKING FINE...but here i didnot know how to pass the date value then the employee id or Employee name value <script> //type="text/javascript"> $(function() { $( "#searchterm" ).autocomplete({ //source:"autosearchwithdate.php?effdate="+$('#effdate').val()+"&"+"empsearch="+$('#empsearch').val(), source: 'autocomplete_salary.php' //source: 'autosearchwithdate.php' }); }); </script> The above coding when i enter the Date column then the next column displays the autoserched value.. That is i need the employee id and names in the autosearch option before the entered date... I have attached the Screenshots Edited April 19, 2022 by selvam1985 Quote Link to comment https://forums.phpfreaks.com/topic/314715-parameter-passing-in-the-autosearch-without-ajax-or-with-ajax/#findComment-1595530 Share on other sites More sharing options...
gizmola Posted April 19, 2022 Share Posted April 19, 2022 Use the code tags button to enter your code in the future. I modified your original post this one time. This code is using mysql_. That api was retired long ago. You should be using mysqli_. Your code is insecure and can be exploited with SQL injections. You should be using prepared statements and bind_param. I'm not going to show you fixed code for that. You should modify all your code accordingly and not use php string concatenation. You already have a drop down that searches and finds the entries < date. Why would you need to pre-populate that drop down? At the point you pre-populate it, it's exactly what your results provide. If you want to have a separate drop down of all the users, then do something like: <html> <form name="input"> <input type="date" id="userdate"> <select name="man" id="man"> </select> <input type="text" size="50" id="searchterm"> </form> <div id="content"></div> Create a new javascript ajax call that Fetches the result and populates the "man" select with elements from the mandata.php result. If you want to constrain the list via the same date field, then add that to your mandata query. <?php // mandata.php include('/include/config1.php'); $select = mysql_query("SELECT man_id, man_name FROM manmaster order by man_name"); $data = []; while ($row = mysql_fetch_array($select)) { $data[$row['man_id']] = trim($row['man_name']); } echo json_encode($data); Update your TEST2.php searchterm query, to utilize the selected man_id from the man select in the search WHERE clause. $manId = (int)$_GET['man']; $query = "SELECT man_id, man_name, join_date FROM manmaster where (man_id LIKE '%$searchTerm%' or man_name LIKE '%$searchTerm%') and join_date <= '$kdt'"; if ($manId > 0) { $query .= " and man_id = $manId"; } $select = mysql_query($query) or die('Query not Executed..!..' .mysql_error()); //etc Quote Link to comment https://forums.phpfreaks.com/topic/314715-parameter-passing-in-the-autosearch-without-ajax-or-with-ajax/#findComment-1595540 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.