karenn1 Posted August 29, 2007 Share Posted August 29, 2007 I have set up a feature on my site, where the user clicks on the link "Phone" and by the switching of divs, the phone number is revealed underneath. The phone number is dynamically driven, so for each member on the list, when you click on "Phone" it reveals the phone number for that person. The link is as follows: <a href="javascript:void(0);" onClick="this.style.display='none'; document.getElementById('<?= $rs_prop["id"]; ?>').style.display='inline'">Phone</a> <span id="<?= $rs_prop["id"]; ?>" style="display:none"><?=$rs_prop["home_no"]; ?></span> So, it's not actually going anywhere or refreshing page, which works for me. My problem is, I want to know how many times the "Phone" link for that SPECIFIC person has been click. I have the following code that I want to use for a click tracker: $sql = 'SELECT * FROM $db.members WHERE id = '.$_REQUEST['id']; $result = mysql_query($sql) or die(mysql_error()); $rs = mysql_fetch_array($result); // Getting Current Month $today = getdate(); $month = $today['month']; $month = strtolower($month); // Assigning data in db to variables if ($result) { $rsid = $rs['id']; $rsemail = $rs['email']; $rstotal = $rs['total']; $dbmonth = $rs['august']; $rsname = $rs['name']; } $newlog = $rstotal + 1; $sql2 = 'UPDATE $db.members SET total = "$newlog" WHERE id = '.$_REQUEST['id']; $result2 = mysql_query($sql2) or die(mysql_error()); $newmonthlog = $dbmonth + 1; $sql2 = 'UPDATE $db.members SET $month = "$newmonthlog" WHERE id = '.$_REQUEST['id']; $result2 = mysql_query($sql2) or die(mysql_error()); I cannot seem to combine the two. How can I track how many times the link for that person has been clicked? This would actually involve calling the $rs_prop['id'] variable so that the total value in the database gets increased by one, but how can I do this? Would the php code above work? Any help would be appreciated!! Thanks, Karen Quote Link to comment https://forums.phpfreaks.com/topic/67196-click-tracker/ Share on other sites More sharing options...
schme16 Posted August 29, 2007 Share Posted August 29, 2007 Combining PHP and JS is annoyingly hard. I've found that one way is to have a small, hidden iframe on the page, that 'post's the variables to a page, and have the link include a submit button... (note! you must have a form around the variables you need posted, those variables can be set by php in a fassion not dissimiler to <form name="form1" mehtod="post" action="process.php" target="hidded_iframe_name"> <input name="var1" type="hidden" value="<?php print $variable_1; ?>" /> </form> <iframe src="" name="hidden_iframe_name" id="hidden_iframe_name" height="0" width="0" style="display:none;"></iframe> or something like that.... ) Quote Link to comment https://forums.phpfreaks.com/topic/67196-click-tracker/#findComment-337156 Share on other sites More sharing options...
karenn1 Posted August 29, 2007 Author Share Posted August 29, 2007 Would the above have the page itself go anywhere? I need it to stay at the spot where the link is clicked. Also with the iframe, how do I make sure the correct ID is sent to process.php each time? I did some research and found some people use the href to call a php function but I couldn't get it to work. Isn't there a clever trick or workaround for that? Quote Link to comment https://forums.phpfreaks.com/topic/67196-click-tracker/#findComment-337339 Share on other sites More sharing options...
Fadion Posted August 30, 2007 Share Posted August 30, 2007 I guess what u need here is AJAX, which would be used to send the update query everytime the link is clicked. I cant help, but im sure u can find tutorials for doing that. Quote Link to comment https://forums.phpfreaks.com/topic/67196-click-tracker/#findComment-337503 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 For AJAX check out Mootools.net Quote Link to comment https://forums.phpfreaks.com/topic/67196-click-tracker/#findComment-337504 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.