Jump to content

Archived

This topic is now archived and is closed to further replies.

recset

Click Counter

Recommended Posts

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

[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);
}

[/code]

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

Now, it does everything that I want it to do (counts hits everytime it is clicked) however, in the URL path,  it adds:
[code]&passit=46[/code]
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:
[code]
&passit=46&passit=22&passit=34&passit=5
[/code]

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



Share this post


Link to post
Share on other sites
I would explode row_quotes into an array and only pass the last var=val

Share this post


Link to post
Share on other sites

×

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.