Jump to content

parameter passing in the autosearch without AJAX or with AJAX


selvam1985
 Share

Recommended Posts

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>

 

 

 

Link to comment
Share on other sites

Posted (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

1044470628_autosearchscreen.thumb.jpg.dad05f7ab79009a818ee2dfca325d4ca.jpg

Edited by selvam1985
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.