SitePoint Sponsor |
|
User Tag List
Results 1 to 16 of 16
Thread: Simple Download count
-
May 28, 2003, 14:44 #1
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Simple Download count
Hi All,
Im try to incorparate a count, so evertime someone clicks a link the database is updated and shows on the display page how many times a file has been clicked/downloaded.
Here's what i have so far and things are not working how I would like them to, if anyone could offer any suggestions to a newbie that would be great !
PHP Code:$dlc = mysql_query("UPDATE kms_dloads SET downloadcount = downloadcount + 1 WHERE downloadcount");
Best Regards
Deano
-
May 28, 2003, 14:48 #2
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
well, if you have all of the links stored in the database, you can setup a script which accepts the ID, then go like so:
PHP Code:if (isset($_GET['id']) && ($id = (int) $_GET['id']) && $id!=0)
{
$url = @mysql_fetch_array(@mysql_query("select url from downloads where id=$id limit 1" ));
if ($url['url'])
{
mysql_query("update downloads set downloadcount=downloadcount + 1 where id=$id");
header("Location: $url[url]" );
}
}
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
May 28, 2003, 14:53 #3
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi Cyborg, Thanks for the rapid reply !
Cound you be a little more specific please, you kinda lost me, here's the script so far :
PHP Code:<?php
// includes
include("conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
$kms_dloads = @mysql_query('SELECT ID, name, description, name, url, size, downloadcount FROM kms_dloads');
$dlc = mysql_query("UPDATE kms_dloads SET downloadcount = downloadcount + 1 WHERE downloadcount");
if (!$kms_dloads) {
die('<p><font color="red" size="2" face="Arial, Helvetica, sans-serif">Error retrieving Links from database!</font><br />'.
'Error: ' . mysql_error() . '</p>');
}
echo("
<table width='768' border='0' cellpadding='0' cellspacing='0' bgcolor='#1A1A34'>
<tr>
<td width='205' height='19' valign='top'><font color='#FFFFFF' size='2' face='Arial, Helvetica, sans-serif'><strong><img src='images/spacer.gif' width='10' height='10'>File
Name</strong></font></td>
<td width='244' valign='top'><font color='#FFFFFF' size='2' face='Arial, Helvetica, sans-serif'><strong>Description</strong></font></td>
<td width='91' valign='top'><font color='#FFFFFF' size='2' face='Arial, Helvetica, sans-serif'><strong>Size</strong></font></td>
<td width='91' valign='top'><font color='#FFFFFF' size='2' face='Arial, Helvetica, sans-serif'><strong>Download</strong></font></td>
<td width='94' valign='top'><font color='#FFFFFF' size='2' face='Arial, Helvetica, sans-serif'><strong>Downloaded</strong></font></td>
</tr>
</table>");
while ($name = mysql_fetch_array($kms_dloads)) {
$id = $name['ID'];
$url = htmlspecialchars($name['url']);
$size = htmlspecialchars($name['size']);
$downloadcount = htmlspecialchars($name['downloadcount']);
$description = htmlspecialchars($name['description']);
$name = htmlspecialchars($name['name']);
echo("<table width='768' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td width='205' height='19' valign='top'><font size='2' face='Arial, Helvetica, sans-serif'><img src='images/spacer.gif' width='10' height='10'>$name</font></td>
<td width='244' valign='top'><font size='2' face='Arial, Helvetica, sans-serif'>$description</font></td>
<td width='91' valign='top'><font size='2' face='Arial, Helvetica, sans-serif'>$size</font></td>
<td width='91' valign='top'><font size='2' face='Arial, Helvetica, sans-serif'><a href=\"http://$url\"> download</a></font></td>
<td width='94' valign='top'><font size='2' face='Arial, Helvetica, sans-serif'><center>$dlc</center></font></td>
</tr>
</table>
Deano
-
May 29, 2003, 08:38 #4
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi All,
I've played with a few ideas and for some reason I can't get it to work.
If anyone could offer a little assistance I would very much appreciate it.
This is what I have so far :
PHP Code:// start of download count
$kms_dloads = @mysql_query('SELECT ID, name, description, name, url, size, downloadcount FROM kms_dloads');
if (isset($_GET['id']) && ($downloadcount = (int) $_GET['id']) && $id!=0)
{
$downloadcount = @mysql_fetch_array(@mysql_query("select downloadcount from kms_dloads where id=$id limit 1" ));
if ($downloadcount['downloadcount'])
{
mysql_query("update downloadcount set downloadcount=$downloadcount + 1 where id=$id" );
header("Location: $downloadcount[downloadcount]" );
}
}
// end of download count
Deano
-
May 29, 2003, 08:46 #5
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
header("Location: $downloadcount[downloadcount]" );
it should be Location :$downloadcount[url], you'll need to select that from the DB as well.Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
May 29, 2003, 08:48 #6
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thx Cyborg, I'll give it a try !
Best Regards
Deano
-
May 29, 2003, 08:58 #7
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does this look something like ?
PHP Code:mysql_query("SELECT ID, FROM kms_dloads UPDATE downloadcount SET downloadcount=$downloadcount + 1 WHERE id=$id" );
header("Location: $downloadcount[url]
-
May 29, 2003, 09:00 #8
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:if (isset($_GET['id']) && ($downloadcount = (int) $_GET['id']) && $id!=0)
{
$downloadcount = @mysql_fetch_array(@mysql_query("select url from kms_dloads where id=$id limit 1" ));
if ($downloadcount['url'])
{
mysql_query("update downloadcount set downloadcount=downloadcount + 1 where id=$id" );
header("Location: $downloadcount[url]" );
}
}
I have no idea why that line is in there, it does nothing as far as I can tell....Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
May 29, 2003, 09:03 #9
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the code above selects the dtabase table and displays the following columns
-
May 29, 2003, 09:15 #10
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I thought this may help matters if i posted the table in the database :
PHP Code:CREATE TABLE kms_dloads (
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
downloadcount int(11),
name TEXT,
description TEXT,
size TEXT,
url TEXT
-
May 29, 2003, 09:31 #11
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
well you'll need to make sure you use ID=$id in my examples, because it is uppercase...
Other than that, it should work properly with what I posted before.Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
May 29, 2003, 09:56 #12
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No luck I'm afraid
PHP Code:// pull the data from the database table
$kms_dloads = @mysql_query('SELECT ID, name, description, name, url, size, downloadcount FROM kms_dloads');
while ($name = mysql_fetch_array($kms_dloads)) {
$id = $name['ID'];
$url = htmlspecialchars($name['url']);
$size = htmlspecialchars($name['size']);
$downloadcount = ($name['downloadcount']);
$description = htmlspecialchars($name['description']);
$name = htmlspecialchars($name['name']);
if (isset($_GET['ID']) && ($downloadcount = (int) $_GET['ID']) && $id!=0)
{
$downloadcount = @mysql_fetch_array(@mysql_query("SELECT downloadcount FROM kms_dloads WHERE ID=$id limit 1" ));
if ($downloadcount['url'])
{
mysql_query("UPDATE downloadcount SET downloadcount=downloadcount + 1 WHERE ID=$id" );
header("Location: $downloadcount[url]" );
}
}
-
May 29, 2003, 10:14 #13
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the code I mentioned is for the actual file you link to, not for display at all....
example, my code goes into download.php, and you call it like this:
<a href="download.php?id=2">Download File</a>Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
May 29, 2003, 10:19 #14
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ahh ! I see ok I need to make a download.php file to pull the file into ..
ok here goes again !
-
May 29, 2003, 12:23 #15
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
edited*
Last edited by Deano; May 29, 2003 at 14:04.
-
May 29, 2003, 14:07 #16
- Join Date
- Mar 2003
- Location
- Derbyshire, UK
- Posts
- 487
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i have created the download.php script here's all thats included :
PHP Code:<?php
// includes
include("conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
if (isset($_GET['ID']) && ($downloadcount = (int) $_GET['ID']) && $id!=0)
{
$downloadcount = @mysql_fetch_array(@mysql_query("SELECT url FROM kms_dloads WHERE ID=$id limit 1" ));
if ($downloadcount['url'])
{
mysql_query("UPDATE downloadcount SET downloadcount=downloadcount + 1 WHERE ID=$id" );
header("Location: $downloadcount[url]" );
}
}
?>
PHP Code:<font size='2' face='Arial, Helvetica, sans-serif'><a href='download.php?id=$url'><img src='images/download.gif' width='14' height='14' border='0' alt='Download File'></a></font>
Any Ideas
Thx Deano
Bookmarks