rascle Posted January 16, 2009 Share Posted January 16, 2009 Hi Say i have a PHP function i want to know if i can link to it using <a hfef> and how would i do it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/ Share on other sites More sharing options...
Maq Posted January 16, 2009 Share Posted January 16, 2009 Why would you ever want to link to a function? Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738657 Share on other sites More sharing options...
RussellReal Posted January 16, 2009 Share Posted January 16, 2009 I agree with maq lol Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738662 Share on other sites More sharing options...
PFMaBiSmAd Posted January 16, 2009 Share Posted January 16, 2009 Browsers can only make http requests to web servers. A link is only a URL that gets requested when that link is clicked. The code on the page that is the target of your link would need to execute the php code you want. If you want more than one action on that page you will need to use a GET parameter on the end of the url that identifies what action you want to perform in the code on that page and your code will need to test what the GET parameter is (a SWITCH/CASE statement would be the most general purpose way of testing for multiple action values.) Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738669 Share on other sites More sharing options...
rascle Posted January 16, 2009 Author Share Posted January 16, 2009 What i mean is with like Javascript if you have a function: <script type="text/javascript"> function goto(){ window.status = www.rasclerhys.com } </script> <a href="#Javascript:goto()"> ^ the code above may be wrong but you get the point. I want to do the same in PHP for example if you have a page that shows results from a MySQL DB and you have a function that creates a MySQL Query deleting the results in the table and you want to have a link so when the user clicks the link saying "Delete Results" it will run the function and then the results will be deleted. < Just an example. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738705 Share on other sites More sharing options...
kenrbnsn Posted January 16, 2009 Share Posted January 16, 2009 You can do that with Javascript, since in runs in the browser. PHP is run on the server. In order for you do to what you want you need to use AJAX techniques. Ken Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738718 Share on other sites More sharing options...
RussellReal Posted January 16, 2009 Share Posted January 16, 2009 php basics 101: php.. is a server side language.. meaning whatever happens on the server side (much like vegas) stays on the server side.. what is recieved by the client (web browser) is html or plain text, output by php. php can not run active with the client, once data gets output, php exits, and the browser handles the html/css/javascript.. what you can do is link to a javascript function.. which connects to aphp page via AJAX then does the actions you wanted php to do.. but you can not link directly to a specific php function unless you make a file with a bunch of functions, and send the function name via get then do $_GET['functionName'](arguements here); ^^ dunno if that'd work.. if not try $function = $_GET['functionName']; $function(arguements here); Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738719 Share on other sites More sharing options...
Maq Posted January 16, 2009 Share Posted January 16, 2009 php.. is a server side language.. meaning whatever happens on the server side (much like vegas) stays on the server side.. I like that... Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738722 Share on other sites More sharing options...
rascle Posted January 16, 2009 Author Share Posted January 16, 2009 I know that PHP is a server side and everything i was just using the Javascript as an example. So basically i will have to go and learn AJAX. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738731 Share on other sites More sharing options...
kenrbnsn Posted January 16, 2009 Share Posted January 16, 2009 AJAX is easy to learn if you use one of the many libraries that have been written. I recommend jquery. For examples on doing a POST via AJAX see Ajax/jQuery.post Ken Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-738742 Share on other sites More sharing options...
rascle Posted January 17, 2009 Author Share Posted January 17, 2009 Ok Thanks Quote Link to comment https://forums.phpfreaks.com/topic/141129-solved-linking-to-a-function-in-php/#findComment-739032 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.