mac08 Posted November 8, 2009 Share Posted November 8, 2009 Hi, I don't know how to explain what I'm trying to do all that great, as I don't have too much experience with php/MySql. I am working on a mobile web site, that has files for download, such as ring tones for example. One of the things I would like to do, is have each category display a total count of how many ringtones are available for that category. For example, some of my categories are: Alternative Rock Alternative Country Pop R&B Sound Effects Now each category has it's own table in my database, with an auto-creasing ID number. Is there any way I can take the highest ID number from each table and have it display next to the category like such: Alternative Rock (106) Alternative (53) Country (82) Pop (176) R&B (98) Sound Effects (302) My second question... Each of my files that are available for download I have stored in a MySql Database. Each file has its own columns such as tone_name, tone_author, date_added, tone_size, tone_length, and dl_count. The dl_count is what I intended on using as my download counter. I start all my files off at 0 download count obviously. What I'd like to do, but what haven't been able to figure it, is how I would make that download count increase every time someone clicked on the download link? I apologize if my lingo was a bit off, hopefully I was able to be as clear as I needed to be to receive some help. Link to comment https://forums.phpfreaks.com/topic/180788-a-file-counter-i-think/ Share on other sites More sharing options...
mac08 Posted November 8, 2009 Author Share Posted November 8, 2009 I've figured out my first question, so I no longer need an answer for that. I'm still stuck on the download counter, if anyone is able to help out with that, I'd appreciate it. Link to comment https://forums.phpfreaks.com/topic/180788-a-file-counter-i-think/#findComment-953838 Share on other sites More sharing options...
corbin Posted November 8, 2009 Share Posted November 8, 2009 You'll need to do that with PHP (which is why I've moved this to the PHP forum. If it's the MySQL parts you're having issues with, I'll move it back). There are two main approaches you can take, and each one has it's issues: --Pass the file through a PHP page. The theory would be that the PHP page would increment the download counter, then spit out the actual content to the client. -That leaves an instance of PHP running until the end of the download --Process the access logs every x minutes. -This could be strenuous on the server if the logs grow rapidly. --Increment the download count on a PHP page and then forward the user to the address of the actual download. -You would have to make sure the user came through the PHP page. I would probably go with the first or third method. If you go with the third method, you'll have to be careful about making sure the client came through the page that counts the downloads (setting a session variable would be the easiest way to do that). Anyway, method and practice are often different, but that should at least help you start ;p. If you already have code, and you're having issues with it, post the area that you're having issues with. Link to comment https://forums.phpfreaks.com/topic/180788-a-file-counter-i-think/#findComment-953851 Share on other sites More sharing options...
chauffeur Posted November 8, 2009 Share Posted November 8, 2009 why not just put a simple 'click' counter on each link that overwrites a simple text file brought back in with 'include'? Link to comment https://forums.phpfreaks.com/topic/180788-a-file-counter-i-think/#findComment-953856 Share on other sites More sharing options...
chauffeur Posted November 8, 2009 Share Posted November 8, 2009 the count code (???) bring it back = <?php include ('works/index1.php'); include ('works/digits.txt'); ?> The script, work it into your download link,= <?php $filename_counts = "digits.txt"; $fp = fopen( $filename_counts, "r" ) or die ("File? What file?<br><br><br>"); $line = fgets( $fp, 16 ); $line=$line+1; // touch ($filename_counts); flock( $fp, LOCK_EX ); $fp = fopen( $filename_counts, "w" ) or die ("File? What file?"); fwrite( $fp, $line); flock( $fp, LOCK_UN ); fclose ($fp); ?> create digits.txt and make it writeable Link to comment https://forums.phpfreaks.com/topic/180788-a-file-counter-i-think/#findComment-953858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.