Adamhumbug Posted February 5, 2020 Share Posted February 5, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/309984-pass-a-variable-into-php-function/ Share on other sites More sharing options...
Barand Posted February 5, 2020 Share Posted February 5, 2020 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/309984-pass-a-variable-into-php-function/#findComment-1574013 Share on other sites More sharing options...
Adamhumbug Posted February 5, 2020 Author Share Posted February 5, 2020 (edited) A perfectly simple answer - thanks so much Edited February 5, 2020 by cyberRobot Removed quote, which included the entire post above. Quote Link to comment https://forums.phpfreaks.com/topic/309984-pass-a-variable-into-php-function/#findComment-1574016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.