Ltj_bukem Posted November 26, 2007 Share Posted November 26, 2007 Hi, I've got a site in which users can download pdf's & wavs, all of the code works fine but I'd like to add features to monitor what information is being downloaded from the site. I have a database with three tables, user, pdf & wav. Is there a simple query to find out, say, the top ten downloaded wavs? I am sure there is but I am fairly new to this, I imagine I'd have to track each downloaded file somehow. If anyone has any ideas to point me in the right direction Id be very grateful. LTJ Quote Link to comment Share on other sites More sharing options...
gtal3x Posted November 26, 2007 Share Posted November 26, 2007 am not a php guru but i wouldent make a direct link to the file but to a another script ex. download?filename=myfile.exe and on that page you could have run a query wich updates the colum wich contains information about myfile.exe like downloads_num, last_download etc, after the query is complite then just call up the file so the user can download it.... i hop this helps Quote Link to comment Share on other sites More sharing options...
Ltj_bukem Posted November 26, 2007 Author Share Posted November 26, 2007 Thats kind of how I've done it, the files aren't actually on in the database themselves, just links to them. What I need is the ability to list a users downloads, I don't quite see how you could save that information in a the databse. Cheers for your help. Quote Link to comment Share on other sites More sharing options...
redarrow Posted November 27, 2007 Share Posted November 27, 2007 SORRY WRONG POST Quote Link to comment Share on other sites More sharing options...
Stooney Posted November 27, 2007 Share Posted November 27, 2007 Basically in the database you'll have: fileId fileName fileLocation etc... then when they go to download something, rather than site.com/file.pfd it'll be site.com/download.php?file=338 (where 338 is a file Id). Then on download.php you just run a simple query to update a column in your users table with what file id they downloaded. This column can contain all of the files they've downloaded in just one field, like 007-332-13-113-553, then just use explode() when your script calls for their download history. Hope it makes sense, I'm not the best at explaining things. Quote Link to comment Share on other sites More sharing options...
Ltj_bukem Posted November 27, 2007 Author Share Posted November 27, 2007 Thanks for that, i've got the first part completed. The users download the pdf's from site.com/download.php?file=338 so each file has a uniqure id, now to sort the query out. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 27, 2007 Share Posted November 27, 2007 what you would have to do is create a extra table which will keep the counts for each download. in that table have the table id, the pdf id wav id, counter, and date.. you can basically doit 2 ways either update the same id with the counter, or just keep adding tot he table each time the file is downloaded and keep it by date. when someone click on download.php?filename=$thisfile&id=fileid&type the query would look something like this. INSERT INTO downloaded_file(id,wavid,pdfid,count,date)values(...) if the file exist and you want to update the counter just use. UPDATE downloaded_file SET counter=+1 WHERE wav or pdf id = id i tried to explain both ways at the same time you can just simplify it and then work your way up. Quote Link to comment Share on other sites More sharing options...
Ltj_bukem Posted November 28, 2007 Author Share Posted November 28, 2007 Right, I've got a table which updates a transaction_id(auto_increment), the pdf_id, count and date. Now, when a user downloads a pdf the table is updated, this works well except that I would like the count to be updated for every record of that pdf_id. For example, if I downloaded the same pdf three times this is what I would get; tr_id id count date 1 1 3 2007-11-28 2 1 2 2007-11-28 3 1 1 2007-11-28 when what I really need is the count to updated for all versions up that pdf_id tr_id id count date 1 1 3 2007-11-28 2 1 3 2007-11-28 3 1 3 2007-11-28 Here's the query... $today = date("y.m.d"); $query = "INSERT INTO pdf_count VALUES ('','$id','', '$today')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); $query =" UPDATE pdf_count SET count=count+1 WHERE id = id"; Any thoughts..? Quote Link to comment 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.