anyone know a good click counter?

sublimer's picture

They have: 41 posts

Joined: Aug 2006

i want to be able to add onto my current database and my current download manager. so what i did was added a row called click_count and figured something like this would work...

<?php
$count
= mysql_query(\"UPDATE downloads WHERE id=\"$id\" SET click_count = click_count + 1\");
?>

I tried to add it to the code for my current download manager but i got a parse error. i think its because it truly isnt doing anything.

here is the query part of my download manager with the working code...

<?php
include 'library/config.php';
include
'library/opendb.php';

$query  = \"SELECT id, name FROM downloads\";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows(
$result) == 0)
{
    echo \"Database is empty <br>\";
}
else
{
    while(list(
$id, $name, $size, $artist, $filename, $filetype, $bootname, $description) = mysql_fetch_array($result))
    {


    <a href=\"download.php?id==
$id;\">=$filePath;</a> <br>
   
   
    }
}

include 'library/closedb.php';
?>

if someone could guide me on how to intergrate my $count query into the download manager it would be much appreciated!

thanks
-drew

Busy's picture

He has: 6,151 posts

Joined: May 2001

You got an error because of the quotes, do either like these:
$count = mysql_query("UPDATE downloads WHERE id=$id SET click_count = click_count + 1");
or
$count = mysql_query("UPDATE downloads WHERE id=".$id." SET click_count = click_count + 1");

sublimer's picture

They have: 41 posts

Joined: Aug 2006

even so, it still won't add. i added the counter query to the original one to make one long one, but my formatting must be wrong or something. here is my code as a whole. i have one query line commented that one works properly. the one that is uncommented works, except for the update part, that leaves the error

Notice: Undefined variable: id in /homepages/36/d106519520/htdocs/download/download.php on line 38
Error, query failed

But it still lets you download files, and to the users they wouldn't notice a difference.

Here is the download manager in whole.

<?php
error_reporting
(E_ALL);
if(isset(
$_GET['id']))
{
    include
'library/config.php';
    include
'library/opendb.php';

   
$id      = $_GET['id'];
   
$query   = \"SELECT name, type, size, path FROM downloads WHERE id = '$id'\";
   
$result  = mysql_query($query) or die('Error, query failed');
    list(
$name, $type, $size, $filePath) = mysql_fetch_array($result);

    header(\"Content-Disposition: attachment; filename=
$name\");
    header(\"Content-length:
$size\");
    header(\"Content-type:
$type\");
   
    readfile(
$filePath);

    include 'library/closedb.php';   
    exit;
}



<html>
<head>
<title>Download</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>

<body>

include 'library/config.php';
include 'library/opendb.php';

//
$query  = \"SELECT id, name FROM downloads\"; //Query that works properly

$query  = \"SELECT id, name FROM downloads UPDATE downloads WHERE id=$id SET click_count+=\";

$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows(
$result) == 0)
{
    echo \"Database is empty <br>\";
}
else
{
    while(list(
$id, $name) = mysql_fetch_array($result))
    {

    //<a href=\"download.php?id==
$id;\">=$name;</a> <br> //Don't display the download list, users must be supplied a link from the site itself
       
    }
}
include 'library/closedb.php';

</body>
</html>
?>

Thanks for the help!
-drew

Busy's picture

He has: 6,151 posts

Joined: May 2001

There is no UPDATE query in this code, change the second SELECT to an UPDATE (or add another).

You might be better just using a single SELECT * then using the if(isset) to filter out that stuff needed.
Are you counting the download or the page view? if its the page view leave it where it is else put it in the isset section

sublimer's picture

They have: 41 posts

Joined: Aug 2006

grr, i've tried probably some 30 different combonations of things to try and get it to work, but it wont!

im trying to make a click counter. everything works, except that the field click_count won't update

here is the code i am currently using!

<?php
error_reporting
(E_ALL);
if(isset(
$_GET['id']))
{
    include
'library/config.php';
    include
'library/opendb.php';

   
$id      = $_GET['id'];
   
$query   = \"SELECT name, type, size, path, click_count FROM downloads WHERE id = '$id'\";
   
$result  = mysql_query($query) or die('Error, query failed');

   
$current = mysql_query(\"SELECT click_count FROM downloads WHERE id='$id'\");
     if (!
$current) {
        echo(\"Error performing query: \" . mysql_error() . \"\");  exit();
     }

    else {

       mysql_query(\"UPDATE downloads SET click_count='click_count + 1' WHERE id='
$id'\");
   
    }

    list(
$name, $type, $size, $filePath) = mysql_fetch_array($result);

    header(\"Content-Disposition: attachment; filename=
$name\");
    header(\"Content-length:
$size\");
    header(\"Content-type:
$type\");
   
    readfile(
$filePath);

    include 'library/closedb.php';   
    exit;
}
?>

if someone can tell me why the field click_count won't change from 0 it would be much appreciated!

thanks, Drew

sublimer's picture

They have: 41 posts

Joined: Aug 2006

i got it working

thanks though!
-drew

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.