graham23s Posted June 5, 2007 Share Posted June 5, 2007 Hi Guys, on my site when a user goes to the "downloads.php" page i update mysql to say downloads+1 to increment the number of downloads each time (but saying that not everyone who goes to the downloads page downloads something) the code is pretty basic: downloads.php // start by grabbing the id...////////////////////////////////////////////////// $id = $_GET['id']; // get the file.../////////////////////////////////////////////////////////////////// $query1 = "SELECT * FROM `uploads` WHERE `id`='$id'"; $result1 = mysql_query($query1); $row = mysql_fetch_array($result1); $file_id = $row['file_id']; $file_name = $row['file_name']; // update the hit counter...//////////////////////////////////////////////////////// mysql_query("UPDATE `uploads` SET `downloads`=`downloads` + 1 WHERE `id`='$id'"); i was thinking a better way would be to place a button there when pressed the download box pops up and THEN it increments mysql but i'm not entirely sure where to go from there i can do the buttons ok: <input type="submit" name="submit" value="downlod" /> so when the button is pressed the downloads starts (it's not a specific filename) so the name of the downloaded file changes depending on what the uploader has called it kinda thing. any help would be great. cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/54283-counting-the-number-of-downloads/ Share on other sites More sharing options...
ted_chou12 Posted June 5, 2007 Share Posted June 5, 2007 Try have a javascript popup that links straight to the file, see the code below: if (isset($_POST['submit'])) { ?> <script type="text/javascript"> window.open("http://www.yourdomain.com/file/link.exe"); </script> <? // start by grabbing the id...////////////////////////////////////////////////// $id = $_GET['id']; // get the file.../////////////////////////////////////////////////////////////////// $query1 = "SELECT * FROM `uploads` WHERE `id`='$id'"; $result1 = mysql_query($query1); $row = mysql_fetch_array($result1); $file_id = $row['file_id']; $file_name = $row['file_name']; // update the hit counter...//////////////////////////////////////////////////////// mysql_query("UPDATE `uploads` SET `downloads`=`downloads` + 1 WHERE `id`='$id'");} ?> Try if this works or not, but I am not confident, just make sure the popup links to your file. Ted Quote Link to comment https://forums.phpfreaks.com/topic/54283-counting-the-number-of-downloads/#findComment-268476 Share on other sites More sharing options...
cooldude832 Posted June 5, 2007 Share Posted June 5, 2007 if you wanted to be modern and the button only activates the download you could you ajax to update the table. I'm not a great ajax person, but tutorials make it sound simple. Quote Link to comment https://forums.phpfreaks.com/topic/54283-counting-the-number-of-downloads/#findComment-268480 Share on other sites More sharing options...
cooldude832 Posted June 5, 2007 Share Posted June 5, 2007 you can invoke ajax off an anchor tag too which could be a direct link to the file download. Quote Link to comment https://forums.phpfreaks.com/topic/54283-counting-the-number-of-downloads/#findComment-268481 Share on other sites More sharing options...
graham23s Posted June 5, 2007 Author Share Posted June 5, 2007 Hi Guys, thanks for the input how hard is ajax? lol the only thing is i don't know the names of the files uploaded i couldn't say : a specificname.doc it would depend on what the user has uploaded would i just stick it in a variable? cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/54283-counting-the-number-of-downloads/#findComment-268584 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.