Jump to content

Methods for conting downloads


Recommended Posts

Yes, you are better spending time up front with db rather than waste hours editing html pages.

Here is update for the stats to give you a little more example on things you can do. This includes total downloads and sorts by most downloads.

<head>
<title>File Download Statistics</title>
</head>
<body>
<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'root', '')
  or die('Could not connect: ' . mysql_error());

mysql_select_db('dbname') or die('Could not select database');

// Performing SQL query for total downloads
$query = 'SELECT sum(count) as dlcount FROM dl_count';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<b>Total Downloads " . mysql_result($result,0,"dlcount") . "</b>\n";
// Free resultset
mysql_free_result($result);

// Performing SQL query for individual downloads
$query = 'SELECT file, count FROM dl_count order by count desc';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num=mysql_numrows($result);

// Printing results in HTML
$i=0;
echo "<table><tbody>\n";
echo "<tr><th>Individual Downloads</th></tr>\n";
while ($i < $num) {
$fname=htmlspecialchars(mysql_result($result,$i,"file"));
$fcount=trim(mysql_result($result,$i,"count"));
echo "\t<tr>\n";
echo "\t\t<td>$fname</td>\n";
echo "\t\t<td>$fcount</td>\n";
echo "\t</tr>\n";
   $i++;
}
echo "</tbody></table>\n";
// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>
</body>
</html>

Next question, one step at a time. First decide what info about the files you would like to present or track, eg. name, category, size, publisher, etc. Then we can make the database to reflect this data. That needs to be done before you can move on to the PHP.

Edited by dman
Link to comment
Share on other sites


thats good, not sure what Individual Downloads are?

Name, Version and size thats all.

got to go now though, need some sleep. I`ll be on 2morow

seriously dman can`t thank you enough, your a star. :thumbup

Link to comment
Share on other sites

Add this table to your database

CREATE TABLE 'dlls' (
'file' VARCHAR( 128 ) NOT NULL ,
'size' VARCHAR( 20 )  ,
'version' VARCHAR( 20 )
);

If you want to make the size and version mandatory add NOT NULL

If you have a list of your files attach it and I will write a little util to convert it into SQL INSERT statements to load up the database.

Edited by dman
Link to comment
Share on other sites

Fully rested now, :D

1. What is a table? do the numbers define the widths of the cells?

CREATE TABLE 'dlls' (

'file' VARCHAR( 134 ) NOT NULL ,

'version' VARCHAR( 138 ) NOT NULL ,

'size' VARCHAR( 128 ) NOT NULL

);

2. What format does the list need to be in?

Edited by Neanderthal
Link to comment
Share on other sites

a table is a database entity that is a group of related data items, like the file info all relates to the file. A database can have many tables, like yours will now have one for files to download, and one for download stats. Think of an HTML table with columns and rows... the columns are the data items you want to track, one row in the table for each record. hope this is clear, you could try reading mysql docs.

a table column can have different data types. varchar is for strings, that is most common. could also be number, logical, date, etc. Yes, the number is the max amount of characters that column will hold. my numbers were just guesses, make it appropriate for your data.

the list can be any text format, i will write util to read it. do you have a list, or still need to make one?

Edited by dman
Link to comment
Share on other sites

thats a little clearer thanx i will dive into the mysql docs when i get chance, i need to learn as much as i can.

So if i use

CREATE TABLE 'dlls' (

'file' VARCHAR( 134 ) NOT NULL ,

'version' VARCHAR( 138 ) NOT NULL ,

'size' VARCHAR( 128 ) NOT NULL

);

the table will be the same as this

Sorry i mean, like the format,

like this; name, version, size

AAAAMON.DLL 5.1.2600.0 25

Or

AAAAMON.DLL,5.1.2600.0,25

Or (the easyest to put together)

Name

Version

Size

A3D.DLL

2.9.0.0

96

Link to comment
Share on other sites

The comma seperated values (name, version, size) would be easiest, but the sequential row listing would work also. (I use visual foxpro for this kind of thing, it has super file and string handling functions)

Think maybe we should change "size" to numeric field so you can use it in stats for total bytes downloaded. The usual rule is to make numbers that will never need math done on them as varchar fields, like the version. Even though it is a number there is no math you can do on it. The size we can use to tally stats, so that can be numeric.

CREATE TABLE 'dlls' (
'file' VARCHAR( 134 ) NOT NULL ,
'version' VARCHAR( 138 ) NOT NULL ,
'size' INT( 11 ) NOT NULL
);

this will create numeric field of type "Integer" (whole numbers)

run "drop table 'dlls'; if you already created it, this will delete current structure

Edited by dman
Link to comment
Share on other sites

visual foxpro! can`t find download link. is it just for msdn subscribers.

i think it has to be the sequential row listing if you don`t mind, otherwise it`s a manual copy paste for each file.

i`ll pm you a link to the list in about 10min.

Link to comment
Share on other sites

You have to buy VFP. It is great language, but MS is trying to kill it in favor of .NET. They are letting it die slowly by not porting it to 64 bit, but it is still very useful.

If you already have the list in that format that is fine, I can read it.

Link to comment
Share on other sites

sent check your pm

btw, i submitted the sql request it returnes this

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''dlls' (

'file' VARCHAR( 134 ) NOT NULL ,

'version' VARCHAR( 138 ) NOT NULL ,

' at line 1

Link to comment
Share on other sites

oops wrong one, try again. :blushing:

Edit,

what about this

CREATE TABLE 'dlls' (

'file' VARCHAR( 134 ) NOT NULL ,

'version' VARCHAR( 138 ) NOT NULL ,

'size' INT( 11 ) NOT NULL

);

is it right?

Edited by Neanderthal
Link to comment
Share on other sites

not sure why thats not working. might have something to do with the quotes.

try this (I tested this time). we are adding a primary key field, dont ask why yet, but we will use it to relate our different tables to one another.

CREATE TABLE `dlls` (
`pk` INT( 5 ) NOT NULL AUTO_INCREMENT ,
`file` VARCHAR( 134 ) NOT NULL ,
`version` VARCHAR( 138 ) NOT NULL ,
`size` INT( 11 ) NOT NULL ,
PRIMARY KEY ( `pk` )
)

Edited by dman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...