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??
Printable View
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??
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...
I'm new to PHP and mySQL so I well like to see some code, please. thank you for your help
any one??:confused:
here is a way to do it.
then in your link have thisPHP 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')");
}
onClick=add_one();
very rough but you should get the idea.
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.
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!!!
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.
When do you need it by?
Do you still need someone to write it?
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.
I've started it, will have to finish it off tonight ;)
cool..thank you da_silvy, your vary helpful:) your one :cool: guy :D
lol :p
thanks m8
nearly finished mate
You could add more features into it, but here is the script:
Put this into download.php
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)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 ();
}
?>
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 ;)
Back again:
Put this in install.php
That creates a table which works with the above script.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 ();
?>
just navigate to that script:
i.e
www.yourhost.com/install.php
then delete/move the file
must not have looked very hard...Quote:
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.
http://www.hotscripts.com/PHP/Script...nload_Systems/
LOL
maybe they weren't to his needs :rolleyes:
eheheheh
damn, that's alot of codes, but oh well...I'll play with it when I get home tonight (me stuck at school again :( :mad: :( )
I keep getting the following when I try running install.php from my server :( :
What's up with that :( and is there another way of counting clicks without using MySQL??Quote:
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
in da_silvy's code change this line in the bold.
you could do it without mysql, but what fun would php be if you can't use mysql. :)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`))";
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
nah, you can have a field with the same name as the table ;)