Jump to content


Photo

download count


  • Please log in to reply
4 replies to this topic

#1 fullyloaded

fullyloaded
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 26 October 2006 - 05:41 AM

hi
im looking for away to count how many times a program was downloaded from my site any idea how thanks

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 06:00 AM

you would make a link to a page and the link would have an id pass to it.  You would then update a field in your database based on the id and then output the filename based on the id.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 October 2006 - 10:27 AM

The id is comming from a session in my example good luck.


url.php 
<?php session_start();

echo "<a href='update_counter.php?id=$id&cmd=update'>goto the page you want</a>";

?>


update_counter.php

<?php session_start();

if($_GET['cmd']=='update'){

$query="UPDATE counter set stats=stats+1 WHERE id='$id'";
result=mysql_query($query);

header("location: To the page where the user wanted to go from the link.php");

}else{

header("location: back to home page if they go to this update page directly");

}
?>


if you use the above defult then your be adding a count of 1 to the stats table but if you added 100 to the stats table and used A - YOUR BE DEDUCTING FROM 100 OK.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 03:19 PM

okay first of all:

if you use the above defult then your be adding a count of 1 to the stats table but if you added 100 to the stats table and used A - YOUR BE DEDUCTING FROM 100 OK.

that makes absolutely no sense at all. I think you are giving an example of an alternate way to keep track, like counting up vs. counting down?

2nd, Can you please explain to me how your code has anything to do with sessions? I mean, I can sorta kinda see that you are providing an example of listing the id's for the links, but I fail to see how that's even remotely necessary? I would assume that one would do a query of some kind to get the id numbers, creating the links in a loop, or some other such similar fashion.  I don't really see the point in carrying over the list of IDs in a session. 

I hope that you are not trying to say that $_GET variables are session variables..
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 October 2006 - 05:00 AM

Crayon Violent sorry if my code made no scence but hopefully this does all the best redarrow.


This code will dispaly 3 links and if the link is pressed will goto a update page and then the user is tacken to the page they wanted.

if the user goes directly to the update page the page takes them to your home page (index.php)

All you got to do is copy and past the code and add the database information.


warning. I have used the ob_start and ob_flush_end on the code to stop header
problams but if you get header erros then you should relly sort them out all
the best redarrow.


The last thing i want to exsplain your see in the query that i got the stats=stats+1 that adds a 1 each time the link is pressed and for the correct page example index.php.

But if you insert in stats a number of 100 you can then count downwords examlpe stats=stats-1 this would take one from the 100 and ecah time deduct 1 from the database.

hope you understand cheers.

databse information.

create database page_stats;

use page_stats;

create table counter(
id int not null primary key auto_increment,
page_name varchar(20) not null ,
stats int not null
);

insert into page_stats (page_name,stats) values (index.php,'1');
insert into page_stats (page_name,stats) values (contact.php,'1');
insert into page_stats (page_name,stats) values (links.php,'1');

test.php

<?php 

// set an array for the links to display and the pages needed.

$page=array(index_page =>'index.php',contact_page =>'contact.php',links_page 
=>'links.php');


// for loop the amount of pages there are. 
for($i=1; $i<2; $i++){


// get the information from the array.

foreach($page as $v => $x){

// echo the three links.

echo "<a href='test_result.php?cmd=update&page_name=$x'>$v</a><br>";

}
 }
?>



test_result.php

<?php

// so the header does not error out a message.
ob_start();

// post the varables.
$page_name=addslashes($_POST['page_name']);
$stats=addslashes($_POST['stats']);

// database connection.

$db=mysql_connect('localhost','xxxxxx','xxxxxxxx');
mysql_select_db('page_stats',$db);


// $_GET the url condirition.

if($_GET['cmd']=='update'){

//get the current url to convert.

$page=$_SERVER['REQUEST_URI'];


//convert the url to use the end condition from the url.
 
$page_name=ereg_replace("^\/+[A_Za-z]+.(php)\?(cmd)\=(update)\&(page_name)\
=",' ',$page);


// query the database to insert the stats to the correct .php page.

$query="UPDATE counter set page_name='$page_name',stats=stats+1 where page_name=
'$page_name' and stats='$stats'";

// query result.

$result=mysql_query($query) or die("query problam error");


// go to a page that the user wanted from the link.

header("location: $page_name");

//else

}else{

// goto the index page if the use goes ot this page directly.

header("location: index.php");

 }

// end the flush for stopping a error header mesage.

ob_end_flush();
?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users