Jump to content

A file counter.. I think?


mac08

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.