Current location: Hot Scripts Forums » Programming Languages » PHP » If someone clicks then {


If someone clicks then {

Reply
  #1 (permalink)  
Old 01-01-06, 07:09 PM
MeAmRussian MeAmRussian is offline
Newbie Coder
 
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
If someone clicks then {

What code would this be? I want some code to be executed if someone clicks on a certain link. So it would be something like

$x = 0
if (someone clicks on this link);
{
$x = $x +1;
}
echo "$x";

Basically, if someone clicks, the number goes up.

Thanks.

Last edited by MeAmRussian; 01-01-06 at 07:13 PM.
Reply With Quote
  #2 (permalink)  
Old 01-01-06, 07:14 PM
hen3rz's Avatar
hen3rz hen3rz is offline
Newbie Coder
 
Join Date: Jun 2005
Location: Australia
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
i dunno if you can count when someone clicks the link but what you could try is make that link open page1 that redirects to the page you want and have page1 count how many times its opened? im not sure if that makes any sense to you if it doesnt just say.
Reply With Quote
  #3 (permalink)  
Old 01-01-06, 07:54 PM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
It depends how you want to count the 'clicks', there are two possible ways:

The PHP Way
Because PHP is server-side, it requires the page to be reloaded everytime a function has to take place, basically you can't execute PHP after the page has loaded. This is what hen3rz is saying; If you choose to use PHP you'll need to reload the page with a variable set in the URL, and then use the $_GET[] function to check if the variable is set, and then add 1 to $x. (Thus saying that someone has clicked the link)

The JavaScript Way
Because JavaScript is client-side, functions can take place 'live', meaning the page doesn't have to be reloaded everytime a function needs to take place. This could simply be done by assigning a JS function to a button on the given page, and then adding 1 to var x everytime the button is pressed.
Reply With Quote
  #4 (permalink)  
Old 01-01-06, 08:40 PM
MeAmRussian MeAmRussian is offline
Newbie Coder
 
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Richard
It depends how you want to count the 'clicks', there are two possible ways:

The PHP Way
Because PHP is server-side, it requires the page to be reloaded everytime a function has to take place, basically you can't execute PHP after the page has loaded. This is what hen3rz is saying; If you choose to use PHP you'll need to reload the page with a variable set in the URL, and then use the $_GET[] function to check if the variable is set, and then add 1 to $x. (Thus saying that someone has clicked the link)

The JavaScript Way
Because JavaScript is client-side, functions can take place 'live', meaning the page doesn't have to be reloaded everytime a function needs to take place. This could simply be done by assigning a JS function to a button on the given page, and then adding 1 to var x everytime the button is pressed.
Hmm... that javascript code would do nicely Can you tell me the code to do it with javascript?

Thanks
Reply With Quote
  #5 (permalink)  
Old 01-02-06, 03:06 PM
Ligx Ligx is offline
Newbie Coder
 
Join Date: Nov 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by MeAmRussian
What code would this be? I want some code to be executed if someone clicks on a certain link. So it would be something like

$x = 0
if (someone clicks on this link);
{
$x = $x +1;
}
echo "$x";

Basically, if someone clicks, the number goes up.

Thanks.
I would try use <type="button" value="MY FILE" onclick="<?PHP $x = $x +1; ?>">
Reply With Quote
  #6 (permalink)  
Old 01-02-06, 03:59 PM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
That will simply make $x = 1 when the page loads, meaning the onclick will be nothing, or 1.
I would recommend posting in the JavaScript Forum, there you might be able to find some helpful JS advice.
Reply With Quote
  #7 (permalink)  
Old 01-03-06, 03:07 AM
knine143 knine143 is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
just a thought...

in php, a simpler way to do "$x = $x + 1;" is simply "$x++;"
Reply With Quote
  #8 (permalink)  
Old 01-04-06, 01:32 AM
Ligx Ligx is offline
Newbie Coder
 
Join Date: Nov 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Richard
That will simply make $x = 1 when the page loads, meaning the onclick will be nothing, or 1.
I would recommend posting in the JavaScript Forum, there you might be able to find some helpful JS advice.
well... then I learned something too! =)
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a way to rotate links after a number of clicks immersion Script Requests 4 10-08-05 10:18 AM
Looking for a way to rotate links after a number of clicks immersion PHP 1 10-07-05 02:16 PM
Javascript that clicks on a link onload? decemuirs JavaScript 2 06-16-05 07:05 AM
Count clicks in a banner rotator mdhall PHP 9 02-29-04 02:58 PM
Automating Button Clicks - Web Page Buddiv The Lounge 4 07-14-03 04:06 PM


All times are GMT -5. The time now is 06:24 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.