|
-
Oct 16th, 2001, 01:18 AM
#1
Thread Starter
Hyperactive Member
PHP to count number of download/clicks
how do I set up something that everytime a user clicks on a link for going to an ad site or to download something using PHP??
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Oct 16th, 2001, 02:04 AM
#2
Conquistador
You can setup a mySQL table, with fields
i.e.
count title target
0 Vb-World http://www.vb-world.net
then when they click, you execute a query to update to:
count title target
1 Vb-World http://www.vb-world.net
if you need code, i might be able to write something suitable for you...
-
Oct 16th, 2001, 02:40 AM
#3
Thread Starter
Hyperactive Member
I'm new to PHP and mySQL so I well like to see some code, please. thank you for your help
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Oct 16th, 2001, 09:16 AM
#4
Thread Starter
Hyperactive Member
any one??
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Oct 16th, 2001, 03:09 PM
#5
here is a way to do it.
PHP Code:
function add_one(){
$link=mysql_connect("localhost","username","password") or die("Error Connecting");
$DB=mysql_select_db("test");
//get the number in the database
$SQL = mysql_query("select hits from tablename")or die("Exit");
//then add one to it and put it back in
while ($row = mysql_fetch_array($sql)) {
$count_entree=$row["hits"];
}
$count_entree++;
mysql_db_query ($db, "INSERT INTO tablename (hits) VALUES ('$$count_entree')");
}
then in your link have this
onClick=add_one();
very rough but you should get the idea.
-
Oct 16th, 2001, 03:25 PM
#6
Thread Starter
Hyperactive Member
is that well also show the number of downloads on there for users to see?? and can you post an ex. page for me?? I'm way too stupid to look at the codes and relize what it do. it's just like when I started working with VB, I didn't know what the code you post do, but me learn, and now me learning PHP so I can use on site. Thank you. btw....HELP ME, I'M STUCK AT SCHOOL.
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Oct 16th, 2001, 09:15 PM
#7
Thread Starter
Hyperactive Member
wow, I just got back from football prac. and came on here and see that no one replyed yet. do I need to beg?? ok, I well. *get's on his knees and puts is fast together* PLEASE, PLEASE, HELP ME BY READING THE ONE POST UP!!!
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Oct 17th, 2001, 01:27 AM
#8
Thread Starter
Hyperactive Member
damn, PHP is confussing....will, thank you for some help, and I'm going to do what you told me to do (which I'm also too lazy to do), research....will....off I go. Thank you.
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Oct 17th, 2001, 01:54 AM
#9
Conquistador
When do you need it by?
Do you still need someone to write it?
-
Oct 17th, 2001, 09:27 AM
#10
Thread Starter
Hyperactive Member
I don't need it right away, I just want to know how to do it so I can use it to count and show the number of downloads of my programs. and this is starting to piss me off and so far, I can't find any good ones off that one site that scoutt told me ooo well. if you post a code and told me how to use it, that well much helpful.
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Oct 17th, 2001, 05:11 PM
#11
Conquistador
I've started it, will have to finish it off tonight
-
Oct 17th, 2001, 08:41 PM
#12
Thread Starter
Hyperactive Member
-
Oct 18th, 2001, 02:53 AM
#13
Conquistador
lol 
thanks m8
-
Oct 18th, 2001, 03:29 AM
#14
Conquistador
-
Oct 18th, 2001, 04:33 AM
#15
Conquistador
You could add more features into it, but here is the script:
Put this into download.php
PHP Code:
<?php
$adminpwd="spoot"; //What do you want your password to be?
$dbhost=""; //The address to the database host
$dbusername=""; //What is the database's password?
$dbpassword=""; //The database's password
$perpage=15; //How many links do you want to show per page
if ($action=="admin"){ //You want to add more downloads to the database
if($password==$adminpwd){
if($submit=="click"){
// The submit button was clicked!
// Get the input for fullname and email then store it in the database.
$connection = mysql_connect ($dbhost, $dbusername, $dbpassword);
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
$query = "INSERT INTO downloads VALUES ('', '$title', '$link', '$description', '0')";
$result = mysql_db_query ("download", $query);
if ($result){
echo "$title was added successfully";
}
else{
echo mysql_errno().": ".mysql_error()."<BR>";
}
//echo $title . $link . $description;
mysql_close ();
}
else{
echo "
<html><body>
<form method=\"post\" action=\"download.php?action=admin&password=$adminpwd\">
Title: <input type=\"text\" name=\"title\"></input><br>
Link: <input type=\"text\" name=\"link\"></input><br>
A small description: <input type=\"text\" name=\"description\"></input><br>
<input type=\"submit\" name=\"submit\" value=\"click\"></input>
</form>
</body></html>
";
}
}
}
elseif($action=="download"){ //Someone wants to download something
if($id){ //Is it a legit download?
// Get the details for the selected download
$connection = mysql_connect ($dbhost, $dbusername, $dbpassword);
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
//Get all the details to download their link
$query = "SELECT * from downloads WHERE ID=$id"; //The SQL query
$result = mysql_db_query ("download", $query); //Query the database
$ltitle = mysql_result ($result, 0, "title"); //Get the link title
$llink = mysql_result ($result, 0, "link"); //Get the actual link
$newnum = mysql_result ($result, 0, "downloads"); //Get current hits
$newnum++; //Add another hit
// Update the hit number for that file
$query = "UPDATE `downloads` SET `downloads` = '$newnum' WHERE `ID` = '$id' LIMIT 1";
$result = mysql_db_query ("download", $query);
mysql_close ();
//The page that is shown when they download something
//It is automatic downloading
echo "
<html><head><meta http-equiv=\"refresh\" content=\"2; url=$llink\">
<body>
<center>
<strong><a href=$llink>$ltitle</a></strong> will start downloading automatically in just a few seconds.<br>
Once the download starts, you can <a href=\"javascript:history.go(-1)\">click here</a> to return.
</center>
</body></html>";
}
}
elseif($action=="show"){ //Show a table of everything in your download Table
$connection = mysql_connect ($dbhost, $dbusername, $dbpassword);
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
//Working out what records to show:
if(!$page){ //They didn't specify a page number
$lowerlimit = 0;
$upperlimit = $perpage;
}
else{
$lowerlimit = $perpage * ($page - 1);
$upperlimit = $lowerlimt + $perpage;
}
//SELECT * FROM `downloads` ORDER BY downloads DESC LIMIT 0, 30
$query = "SELECT * FROM downloads ORDER BY downloads DESC LIMIT $lowerlimit, $upperlimit"; //Query to Show the proper records for that page, with the most popular at the top
$result = mysql_db_query ("download", $query); //Execute that query
if ($result){
//You can adjust this table to how you want it
echo "<table width=\"100%\">";
echo "<tr><td width=\"33.3%\"><b><center>Link</center></b></td><td width=\"33.3%\"><b><center>Description</center></b></td><td width=\"33.4%\"><b><center>Downloads</center></b></tr>";
$numOfRows = mysql_num_rows ($result); //How many rows were returned?
for ($i = 0; $i < $numOfRows; $i++){ //Loop thru each record
$title = mysql_result ($result, $i, 1); //Get the title
$id = mysql_result ($result, $i, "id"); //Get the download ID
$desc = mysql_result($result, $i, "description"); //get the description
$downloads = mysql_result($result, $i, "downloads"); //get the description
echo "<tr><td><a href=\"download.php?action=download&id=$id\"><center>$title</center></a></td><td><center>$desc</center></td><td><center>$downloads</center></td></tr>";
} //Close the for loop
echo "</table>";
} //Close if($result)
else{
echo mysql_errno().": ".mysql_error()."<BR>";
} //Close the else statement
mysql_close ();
}
?>
Any questions about that?, just ask me because as I wrote it, I should be able to answer some questions about it (should be able to)
How to use it.
Set up all the values in the first part of the script. I.E:
$adminpwd="spoot"; //What do you want your password to be?
$dbhost=""; //The address to the database host
$dbusername=""; //What is the database's password?
$dbpassword=""; //The database's password
$perpage=15; //How many links do you want to show per page
They are the values for 15 per page, admin password of spoot and the database is set up for using on the local host 
i suggest also running the install script which i will put in below all this...
1. To add links.
Navigate to http://www.yourhost.com/download.php...dmin&password=*yourpassword*
Obviously replace *yourpassword* with spoot or whatever you have changed it to.
2. To show every link in your table
Navigate to www.yourhost.com/download.php?action=show
It will display a table showing title, download link, description and number of downloads/clicks
You can edit this table code.
Notice how the href to a link is in the form of
http://www.yourhost.com/download.php...=download&id=3
id is an auto_increment number in the database which I used to index the downloads easily
3. To link directly to a download, and still
count it in "downloads count" or "click count", you need to find out the items ID, such as 1 for the first item etc
I suggest using method 2 to find out the id.
The direct link can then be added to your page in the form of:
<a href="download.php?action=download&id=1">Download Item 1</a>
This would provide a link, that, when clicked, will direct them to the download site, add 1 to the download/click count and then allow them to download it.
And again, if you have any questions, just ask me 
I have to post the install script, please hold tight for 2 hours
-
Oct 18th, 2001, 06:17 AM
#16
Conquistador
Back again:
Put this in install.php
PHP Code:
<?php
//Just fill in these details:
$dbhost=""; //The address to the database host
$dbusername=""; //What is the database's password?
$dbpassword=""; //The database's password
$dbname="test_database";
$connection = mysql_connect ($dbhost, $dbusername, $dbpassword);
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
//Create the table
$query = "CREATE TABLE `downloads` (`ID` TINYINT NOT NULL AUTO_INCREMENT, `title` TEXT NOT NULL, `link` TEXT NOT NULL, `description` TEXT NOT NULL, `downloads` TINYINT NOT NULL , PRIMARY KEY (`ID`))";
$result = mysql_db_query ($dbname, $query);
if ($result)
echo "Table 'downloads' was successfully created! Please move this file from public access now.";
else
echo mysql_errno().": ".mysql_error()."<BR>";
mysql_close ();
?>
That creates a table which works with the above script.
just navigate to that script:
i.e
www.yourhost.com/install.php
then delete/move the file
-
Oct 18th, 2001, 08:53 AM
#17
Originally posted by scsa20
I don't need it right away, I just want to know how to do it so I can use it to count and show the number of downloads of my programs. and this is starting to piss me off and so far, I can't find any good ones off that one site that scoutt told me ooo well. if you post a code and told me how to use it, that well much helpful.
must not have looked very hard...
http://www.hotscripts.com/PHP/Script...nload_Systems/
-
Oct 18th, 2001, 09:38 AM
#18
Conquistador
LOL
maybe they weren't to his needs 
eheheheh
-
Oct 18th, 2001, 02:52 PM
#19
Thread Starter
Hyperactive Member
-
Oct 19th, 2001, 12:41 AM
#20
Thread Starter
Hyperactive Member
I keep getting the following when I try running install.php from my server :
1064: You have an error in your SQL syntax near '`downloads` (`ID` TINYINT NOT NULL AUTO_INCREMENT, `title` TEXT NOT NULL, `link`' at line 1
What's up with that and is there another way of counting clicks without using MySQL??
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Oct 19th, 2001, 01:57 AM
#21
in da_silvy's code change this line in the bold.
Code:
$query = "CREATE TABLE `downloads` (`ID` INT(11) NOT NULL AUTO_INCREMENT, `title` TEXT NOT NULL, `link` TEXT NOT NULL, `description` TEXT NOT NULL, `downloads` INT(11) NOT NULL , PRIMARY KEY (`ID`))";
you could do it without mysql, but what fun would php be if you can't use mysql. 
I think that will fix it. if not just take out all the not nulls except this one
downloads` (`ID` INT(11) NOT NULL AUTO_INCREMENT,
do not take the not null out of that one.
also I don't think you can have a row the same name as the table. might want to check with da_silvy on that one since he wrote it. that is my guess
-
Oct 19th, 2001, 02:48 AM
#22
Conquistador
nah, you can have a field with the same name as the table
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|