Jump to content


Photo

Click Counter


  • Please log in to reply
1 reply to this topic

#1 recset

recset
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 10 September 2006 - 09:30 PM

I am trying to create a click counter for records in my database with the following code:

// *** Hits Counter ***
$urlparam = "passit";
$ckrs = "quotes"; //used for identification
if (!isset($HTTP_SERVER_VARS["QUERY_STRING"])) {
  $HitLink = $HTTP_SERVER_VARS["PHP_SELF"] . "?" . $urlparam . "=";
} else {
  $HitLink = $HTTP_SERVER_VARS["PHP_SELF"] . "?" . $HTTP_SERVER_VARS["QUERY_STRING"] . "&" . $urlparam . "=";
}
if (isset($HTTP_GET_VARS[$urlparam])) {
  $tableName = "wisdom_backup";
  $fieldName = "ID";
  $hitsfield = "Counter";
  $urlfield = "PATH";
  // Get the Hits number and update it.
  $rsCon = "vlot";
  $IdSource = "select * from " .  $tableName . " where " . $fieldName . " = " . $HTTP_GET_VARS[$urlparam] . "";
  $rsId = mysql_query($IdSource, $$rsCon) or die(mysql_error());
  $row_rsId = mysql_fetch_assoc($rsId);
  $hiturl = $row_rsId[$urlfield];
  $next = $row_rsId[$hitsfield] + 1;
  $upd = "update " . $tableName . " set " . $hitsfield . " = " . $next . " where " . $fieldName . " = " . $HTTP_GET_VARS[$urlparam] . "";
  $rsId = mysql_query($upd, $$rsCon) or die(mysql_error());
  $rsId = null;
  header("Location: " . $hiturl);
}


And this is the code for the actual link:
<a href="<?php echo $HitLink . $row_quotes["ID"] ?>">Download</a>

Now, it does everything that I want it to do (counts hits everytime it is clicked) however, in the URL path,  it adds:
&passit=46

the '46' refers to the record ID, now if a user keeps on clicking different record ID's, it will keep on adding the 'passit' url parameter, for example it would look like:
&passit=46&passit=22&passit=34&passit=5

And so on and so on. Is there a way to clear the url parameters once the link has been clicked, but still store the data that its supposed to store??





#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 11 September 2006 - 01:05 AM

I would explode row_quotes into an array and only pass the last var=val
Why doesn't anyone ever say hi, hey, or whad up world?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users