Jump to content

Pass a variable into PHP function


Adamhumbug

Recommended Posts

Hi All,

I have a function that i want to pass a variable into so that i can do some SQL on it.

The information that i want to pass into it is a data-id on a button that is used to trigger the function.

The button that will be clicked is this

<div class='modaltrigger btn btn-primary' data-id='$itemId' data-toggle='modal'>Manage</div>

This button is being created by another function.

I would like to know either how i pass the variable from one function to another or how i pass it from the data-id to the function in php.

Thanks in advance.

Link to comment
Share on other sites

To pass the value from the client click to PHP requires AJAX. 

for example, javascript onclick handler would

$.get(
    "ajax-handler.php",
    {"id" : $(this).data("id")},
    function (response) {
      // handle reponse
    }  ,
    "TEXT"
)

Then in "ajax-handler.php"

<?php
$result = myfunction($_GET['id']);

function myfunction (id) {
   // do something with id
   // return result
}
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.