Display the sum of two id's amount of clicks?

Post your Click counter digestion problems here
Post Reply
MClick
Posts: 2
Joined: Sat Sep 29, 2012 7:29 am

Display the sum of two id's amount of clicks?

Post by MClick »

Version of script: 1.2

Hi, displaying number of clicks works fine and all that. But I'm trying to find a solution to add the sum of clicks of one id with the sum of clicks of an other id and then display the total.

Basically if id 1 has 10 clicks and id 2 has 5 clicks I want to display 15 (id1+id2) as the total.

Is this possible?

I've tried different solutions in the manners of:
<script language="Javascript">ccount_display('1')+('2')</script>
But that was obviously too simple :P

Thanks in advance!
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Re: Display the sum of two id's amount of clicks?

Post by Klemen »

In display.php if you find

Code: Select all

function ccount_display(id) {
    document.write(ccount_link[id]);
}
and paste this below:

Code: Select all

function ccount_sum(id1, id2) {
	var sum = ccount_link[id1] + ccount_link[id2];
    document.write(sum);
}
You could then use

Code: Select all

<script language="Javascript">ccount_sum('1', '2')</script>
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
MClick
Posts: 2
Joined: Sat Sep 29, 2012 7:29 am

Re: Display the sum of two id's amount of clicks?

Post by MClick »

Klemen wrote:...brilliant solution...
That worked perfectly, thank you so much! And thank you for such a quick response.
robsterling
Posts: 3
Joined: Thu Jan 28, 2016 6:20 pm

Re: Display the sum of two id's amount of clicks?

Post by robsterling »

Is there a current version of this script available? It looks like this is for an older version of CCount.
robsterling
Posts: 3
Joined: Thu Jan 28, 2016 6:20 pm

Re: Display the sum of two id's amount of clicks?

Post by robsterling »

I tried rewriting it like this, but it doesn't work.

Code: Select all

function ccount_sum (id1, id2, id3, id4, id5)
{
   var sum = ccount[id1]['c'] + ccount[id2]['c'] + ccount[id3]['c'] + ccount[id4]['c'] + ccount[id5]['c'];
   document.write(sum).formatThousands('<?php echo $ccount_settings['notation']; ?>'));
}
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Re: Display the sum of two id's amount of clicks?

Post by Klemen »

This should do the trick in 2.x:

Code: Select all

function ccount_sum(id1, id2)
{
	var sum = ccount[id1]['c'] + ccount[id2]['c'];
	document.write(sum.formatThousands('<?php echo $ccount_settings['notation']; ?>'));
}
Then to display:

Code: Select all

<script>ccount_sum('1', '2')</script>
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
robsterling
Posts: 3
Joined: Thu Jan 28, 2016 6:20 pm

Re: Display the sum of two id's amount of clicks?

Post by robsterling »

That works. Thanks, man.
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Re: Display the sum of two id's amount of clicks?

Post by Klemen »

This feature (and some additional display options) has been included in version 2.1.0 that has been released just now.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply