0

Trying to pass variable into a HTML modal, run a query and display info based on the id... I can pass the parameter into the HTML with this but I need it at the end of a SQL WHERE statement at the end of a query...

my script is here. Im thinking I need some ajax to accomplish this. I created a fiddle

http://jsfiddle.net/rbla/y7s5tf3p/

<script>

$(document).on("click", ".open-AddBookDialog", function () {
 var myBookId = $(this).data('id');
 //$(".modal-body #bookId").val( myBookId );
 document.getElementById("bookId").innerHTML = myBookId; 

});

</script>

The variable gets inserted into the HTML , but I need to get the data-id into a php variable and not HTML so that I can run a query...

Here is the PHP file I have

<?php

$id = ( this is where the data-id needs to be );

$sql = oci_parse($conn, select * from movies m where id=:id");

oci_bind_by_name($sql, ':id', $id);

oci_execute($sql, OCI_DEFAULT);

$objResult = oci_fetch_array($sql);
?>
Ronald
  • 557
  • 1
  • 9
  • 26

1 Answers1

0

Yes, you will need AJAX to do what you want.

Note that $(this).data('id') will get the value of a tag attribute similar to:

<input type="text" data-id="mother" id="17" />

It would grab the value mother, not 17.

This below code sample is probably similar to what you will need to build:

javascript/jQuery:

$(document).on("click", ".openSlickModal-1", function () {
    var myMovieId = $(this).data('id');
    $.ajax({
        type: 'post',
         url: 'my_ajax_processor.php',
        data: 'MovieID=' +myMovieId,
        success: function(d){
            alert(d); ////Just for testing: disable after receiving the correct response
            $("#movie").html(d);
        }
    });

});

my_ajax_processor.php:

<?php
    $id = $_POST['MovieID'];
    die('Received: ' .$id); //Just a test: disable this after receiving the correct response

    //do your query using the $id
    $out = 'Whatever you create (HTML or plain text) after your query
    echo $out;
?>

Additional References:

dynamic drop down box?

Prevent Page Load on Jquery Form Submit with None Display Button

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • I use this for my links that open the modals – Ronald Apr 26 '16 at 21:43
  • VIEW MOVIE – Ronald Apr 26 '16 at 21:43
  • Oh, okay then. Just a bit unusual, but perfectly acceptable. You can use either `id=` or `data-id=`, but `id=` is more common. Does the above code give you an idea how to proceed? *If you have further questions, please leave another comment.* – cssyphus Apr 26 '16 at 22:13
  • I just updated my entire question, added some php and created a jsfiddle. I tried what you said unsuccessfully. if you could assist - I would be appreciative... – Ronald Apr 27 '16 at 13:59