kyleabaker Posted October 7, 2006 Share Posted October 7, 2006 Hey guys, I made a links page on my website recently and I wanted it to increment a number in my MySQL database for the individual link entry in the database each time it is clicked. I have the page php setup to print out each row in the links table from my database in the format of...[code]($ clicks) <a href='$ url' onClick='increment($ number)'>$ name</a>[/code]...so it looks like (45) Link1 or something like that. My real question is how do I do something like this... [code] < script> function increment (n) { <- ? php mysql _ query(' UPDATE links WHERE number = n $ clicks = $ clicks + 1 ') ; ? > } < / script> [/code] ...where n is the varible used in the javascript function. I'm guessing they don't follow through and aren't usable in the php code? if not how could I make use of them? or is there a better way to do this? I had to mess up to format of that code above before it would post this message, but maybe you can still understand my question. Also, I wasn't sure if php could be used in the middle of a javascript function in this way, but if not maye there is another better way to do what I'm trying to do. Thanks in advanced, kyleabaker Quote Link to comment Share on other sites More sharing options...
trq Posted October 7, 2006 Share Posted October 7, 2006 Javascript happens on the client, while php on the server. The only way you can get javascript variables into php is to submit them back to the server. Many ways to do this, most need a page refresh, or you could try using some ajax. Quote Link to comment Share on other sites More sharing options...
kyleabaker Posted October 7, 2006 Author Share Posted October 7, 2006 Oh I see. Before I go test this, what would happen if I just added the correct php script to the onClick event of each url plugging in the proper number so they are all set correctly? Would the onClick event actually run the php script? or would there be anyway to make the onClick even run the code if I can insert the exact script in each url's onClick event? Thanks in advanced! Quote Link to comment 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.