0

I have one PHP file name as report.php in which I also created one script for id using post type which I have one post type of ajax for pass id. I want to use that post type id in my report.php query to comparing id. so how can I get that post id in my $str query to compare?

<script type="text/javascript">
    $(document).ready(function(){
      $('#project').on('click',function(){
        var pID = $(this).val();
        alert(pID);
        if(pID){
          $("#developer").show();
          $.ajax({
          type:'POST',
          url:'report1.php',
          data:'id='+pID,
          success:function(html){
            $('#developer').html(html);
          }
          }); 
        }
      });
    });
</script>

In Below query, I want to compare post type id with given value.

$str = "SELECT GROUP_CONCAT(CONCAT((u.firstname),' ',(u.lastname))) as dname, p.name, GROUP_CONCAT(t.hours)as spent_hrs, SUM(t.hours) as tot_spent,t.spent_on FROM time_entries as t 
    INNER Join projects as p on p.id = t.project_id 
    INNER Join users as u on u.id = t.user_id 
    where p.id=$_POST[id] and u.id=6 
    GROUP By p.id,t.spent_on ";
Albert Lazaro de Lara
  • 2,540
  • 6
  • 26
  • 41

3 Answers3

1

change your ajax request data:

$.ajax({
    type:'POST',
    url:'report1.php',
    data:'id:'+pID,
    success:function(html_data){
      $('#developer').html(html_data);
    }
}); 

then in report1.php page you can get id using $_POST['id'];

B. Desai
  • 16,414
  • 5
  • 26
  • 47
0
$('#developer').on('click',function(){
        var dID = $(this).val();
        if(dID){
            $.ajax({
                type:'POST',
                url:'report1.php',
                data: 'pid='+pID+'did='+dID,
                success:function(html_data){
                    // console.log(html);
                  $('#developer').html(html_data);
                 }  
            }); 
        }
    });
-1

you can batter idea see this answer further query you can ask a community jQuery Ajax POST example with PHP

$('#devloper').on('click',function(){
        var dID = $(this).val();


      });
Community
  • 1
  • 1
vinny
  • 128
  • 1
  • 12