2 Pages V   1 2 >  
Reply to this topic Start new topic

Rating 3 V
 [PHP] - [Simple download counter] - [Gio], for the confused one
_*Gio_*
post Sep 5 2004, 03:26 PM
Post #1





Guests






Ok this tutorial will simply show you how to display the number of times a certain file has been downloaded. It can also be altered to show number of times it was clicked.

The SQL

CODE
CREATE TABLE counter (
id int(5) DEFAULT '0' NOT NULL auto_increment,
FileName varchar(50) NOT NULL,
FileURL varchar(255) NOT NULL,
Count int(5) NOT NULL,
PRIMARY KEY (id)
);


Basically the sql table has fields for the id, which is unique for each file, the file name, the file url, and the count.

The viewing of the file.

View.php

CODE
<?php

include "connect.php";

$x ="SELECT * from counter order by FileName";
$result = mysql_query($x) or die
("Could not execute query : $x." . mysql_error());

echo "<p align=center><b>File Download</b></p>";
echo "<ol>";

while ($row=mysql_fetch_array($result))
{
$id = $row["id"];
$FileName = $row["FileName"];
$FileURL = $row["FileURL"];
$Count =$row["Count"];


echo "<li><a href=download.php?id=$id>$FileName</a></li>";
}
?>


First you connect then you select the downloads and order them by the filename, and if sql will not connect the script dies immediately. Then you echo File Download fetch the resaults of your previous query and order them out to look pretty, then link them!

Now for the download counter, and of course the download!

Download.php


CODE
<?php

// Database connection stuff here

$x ="SELECT * from counter where id='$id'";
$result = mysql_query($x) or die
("Could not execute query : $x." . mysql_error());

while ($row = mysql_fetch_array($result))
{
$id = $row["id"];
$FileName = $row["FileName"];
$FileURL = $row["FileURL"];
$Count = $row["Count"];

header('Location: '.$FileURL);

$x ="update counter set Count=Count+1 where id='$id'";
$result = mysql_query($x) or die
("Could not execute query : $x." . mysql_error());

}

?>


Ok I shall explain this part as well. First you query the database and get the id of the file selected. Then it finds it or the script automatically dies. Define the id filename fileurl and the times downloaded. It redirects the user to the file, and adds 1 more number to the download stats.
Go to the top of the page
 
_*Jay_*
post Sep 5 2004, 03:34 PM
Post #2





Guests






nice tut, nice to see p2l can write them as well as provide links to them victory.gif
Go to the top of the page
 
_*Gio_*
post Sep 5 2004, 03:35 PM
Post #3





Guests






Yah I am still not sure why Faken never premoted me to staff, but I am just trying to get the p2l tut count up so were not just an indexing service.
Go to the top of the page
 
_*Anarchy_*
post Sep 5 2004, 04:40 PM
Post #4





Guests






very useful... victory.gif
Go to the top of the page
 
_*Gio_*
post Sep 5 2004, 09:32 PM
Post #5





Guests






Thanks dude, I was wondering if anyone actually read them.
Go to the top of the page
 
_*SERB-4-LIFE_*
post Sep 7 2004, 01:30 AM
Post #6





Guests






i do i read every single one in the forum and heaps from the site victory.gif
Go to the top of the page
 
_*Andy_*
post Sep 7 2004, 02:29 PM
Post #7





Guests






^^ nice... alot of that confuses me as well as it has been explained.

PHP is not my thing, feels good when you set something up though, HAHA. Nice tut, will definatley come in handy!

Thanks,
Andy smile.gif
Go to the top of the page
 
_*SERB-4-LIFE_*
post Sep 7 2004, 05:21 PM
Post #8





Guests






well its not my thing but it is when someone does all the code for me and tells me how to use it victory.gif but all i can write in php is <?php ?> thats it victory.gif

so thats whats so special about this site, it gives me the code and its easy to use
Go to the top of the page
 
_*Gio_*
post Sep 8 2004, 02:41 PM
Post #9





Guests






Hey I am always happy to provide. Just do not ask for everything, it is easier sometimes to try to do it yourself then ask for help with what ever your not getting. That way you dont seem greedy.
Go to the top of the page
 
_*SERB-4-LIFE_*
post Sep 8 2004, 05:16 PM
Post #10





Guests






i did as much as i could with no help now i need it victory.gif
Go to the top of the page
 
_*Gio_*
post Sep 8 2004, 06:05 PM
Post #11





Guests






Sorry but I do not think of

CODE
<?

?>



As real coding, I mean put some real effort into it. Things will not always be done for you for free. Sometimes you gotta give alittle to get alittle.
Go to the top of the page
 
_*SERB-4-LIFE_*
post Sep 8 2004, 10:49 PM
Post #12





Guests






yeh i know victory.gif is there a site where it learns u step by step php ??
Go to the top of the page
 
_*Jay_*
post Sep 9 2004, 11:57 AM
Post #13





Guests






i'd love to create such a site if i ever got time
Go to the top of the page
 
_*Gio_*
post Sep 9 2004, 02:43 PM
Post #14





Guests






That would take sooo long though, try W3 Schools. They teach you stuff step by step and even provide tests for you to take.
Go to the top of the page
 
_*Anarchy_*
post Sep 12 2004, 03:48 PM
Post #15





Guests






yeah, w3schools look great, i just started, and it looks like they provide pretty much everything.
Go to the top of the page
 
_*Gio_*
post Sep 12 2004, 05:05 PM
Post #16





Guests






Kind of, pretty much as basic as it gets.
Go to the top of the page
 
_*SERB-4-LIFE_*
post Sep 13 2004, 04:34 AM
Post #17





Guests






yeh but it takes a while to finish all of it
Go to the top of the page
 
_*Gio_*
post Sep 16 2004, 12:46 PM
Post #18





Guests






Anyways back on topic, SERB did you decide to use this one?
Go to the top of the page
 
_*SERB-4-LIFE_*
post Sep 20 2004, 02:00 AM
Post #19





Guests






yeh i did when u come to msn ull give me a leson on how to use this victory.gif i want to use it but its 2 complicated so ull help me out victory.gif
Go to the top of the page
 
_*Gio_*
post Sep 20 2004, 12:46 PM
Post #20





Guests






I will do, just post any problems with it here so they can be fixed immediately.
Go to the top of the page
 

2 Pages V   1 2 >
Reply to this topic Start new topic
Forum Options & Statistics
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 9th February 2010 - 01:44 PM
Pixel2Life Home Advanced Search Get Started Credit Corner Get Started Credit Corner Forum Options The P2L Staff Top Overall Posters Top Today Posters Today Active Topics