Re: how to call a function when somebody click a link?
- From: "Mateusz Markowski" <mateusz@xxxxxxxxxxx>
- Date: 4 Nov 2006 01:56:56 -0800
yangsuli@xxxxxxxxx napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)
i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link
then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.location.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(
now i am thinking using a flag,say,$functioncall,
href=$_server[request_url]&functioncall=1
then if functioncall==1,call that function
but is it right?
is there some way simple to do that?
PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call=helloworld
and in your file script.php such code:
if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}
Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
.
- Follow-Ups:
- Re: how to call a function when somebody click a link?
- From: yangsuli@xxxxxxxxx
- Re: how to call a function when somebody click a link?
- References:
- how to call a function when somebody click a link?
- From: yangsuli@xxxxxxxxx
- how to call a function when somebody click a link?
- Prev by Date: Re: How to get visitor host name?
- Next by Date: Re: how to call a function when somebody click a link?
- Previous by thread: how to call a function when somebody click a link?
- Next by thread: Re: how to call a function when somebody click a link?
- Index(es):
Relevant Pages
|