0

i want to get sub destination id which is coming from jquery i want it in this mysql query

 <a href="#small_add" data-id="<?php echo $id;?>" type="button" data-toggle="modal" class="open-AddBookDialog">Details</a></div>
         <script>
                $(document).on("click", ".open-AddBookDialog", function () {
                 var myBookId = $(this).data('id');
                 $(".modal-body #bookId").val( myBookId );
                $('#small_add').modal('show');
                });
                </script>

    $sub_desti_id=???

     $small_hotel="SELECT * FROM small_add WHERE sub_dest='$sub_desti_id' ";
        $small_hotel1=mysql_query($small_hotel);
Vivek
  • 47
  • 6

1 Answers1

0

PHP runs on the server, JavaScript (jQuery) runs on the browser. You can use PHP to write to JS, but you can't do modifications in PHP with JS.

To do what you want, you have to use ajax, for example. To do this, You have to do a post to the same page with a parameter to do what you want. For example:

function ajaxCall() {
   var _sub_desti_id = /* set you variable*/
   $.ajax({
      url: 'index.php',
      data: {function:query, sub_desti_id:_sub_desti_id},
      success: function(data) {
          //do what you want with the result of the query
      }
   })
}

and in your php you use something like

if ($_REQUEST['function'] == 'query') {
     $sub_desti_id = $_POST['sub_desti_id'];

     $small_hotel="SELECT * FROM small_add WHERE sub_dest='$sub_desti_id' ";
     $small_hotel1=mysql_query($small_hotel);

     $id = //get your id from the query;

     echo '<a href="#small_add" data-id="'.$id.'" type="button" data-toggle="modal" class="open-AddBookDialog">Details</a>';
}

I dont have an enviroment to test it write now, but I think that you can get the ideia.

danielpm
  • 125
  • 5
  • 20
  • not working sir there is a Pop up div i want that id in that pop up div to fetch data from database is there any soluation please provide it – Vivek Mar 03 '16 at 11:24
  • @Vivek wich is the id of the element on the modal where you want to display the id? – danielpm Mar 03 '16 at 11:39
  • See my update. If you want to set the id of the modal after the query, you can create it with php after the query. – danielpm Mar 03 '16 at 11:48