Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/67196-click-tracker/
Share on other sites

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....

 

)

Link to comment
https://forums.phpfreaks.com/topic/67196-click-tracker/#findComment-337156
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/67196-click-tracker/#findComment-337339
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.