SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: counting

  1. #1
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    counting

    Hi all,
    Im writing a download system and all works perfectly well accept for when a users clicks on download the script counts the file twice

    Here's script so far :

    PHP Code:
    //select count column and update when applicable
        
    $result mysql_query("SELECT ID,url,count FROM kms_dloads WHERE ID='$id'"); 
        
    $row mysql_fetch_array($result); 
        
    $ID        $row['id']; 
        
    $count      $row['count']; 
        
    $count      $count 1
        
    $update     "UPDATE kms_dloads SET count='$count' WHERE ID='$id' "
        
    $updatesql  mysql_query($update);
        
        
    mysql_query("UPDATE kms_dloads SET count=count+1 WHERE ID='$id'"); 
    Anyone have any ideas ?

    Best Regards
    Deano

  2. #2
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am having browser problems but how about

    //select count column and update when applicable
    $result = mysql_query("SELECT ID,url,count FROM kms_dloads WHERE ID='$id'"
    );
    $row = mysql_fetch_array($result
    );
    $ID = $row['id'
    ];
    $count = $row['count'
    ];
    $count = $count + 1
    ;
    $update = "UPDATE kms_dloads SET count='$count' WHERE ID='$id' "
    ;
    $updatesql = mysql_query($update
    );


    The problem seems to be the second count+1 and I would look around in that area.

    Nice coding.

    peace


  3. #3
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx edshuck,

    I shall give it a try

    Cheers
    Deano

  4. #4
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It worked perfectly...

    Thx again edshuck !

  5. #5
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are welcome!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •