Pages: [1]   Go Down
Send this topic | Print
Author Topic: Help me create my perfect mysql counter :D  (Read 853 times)
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« on: September 16, 2008, 05:32:55 AM »

I want to create a download counter for my new download page here.

As you can see on my url theres a bit that has link=blahblah, what I need it to do is count each hit to every link inputted there. The script needs to record Title, URL, Hits. They should only only count unique hits aswell.

I would want it preferably on the "Click Here to Save"
Maybe like this... http://www.mysite.com/addcount.php?title=my page&url=http://thedownloadloadlink.com


I just about know how to make a simple mysql counter, but because I need to store multiple page hits, i dont have any idea how I would do it.
Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
Ðaz
Web Master & Coder for Life
Loyal 110MB Member
*******
Offline Offline

Posts: 3219

Gone with the wind.


WWW
« Reply #1 on: September 16, 2008, 06:17:02 AM »

What don't you understand? Create 3 columns in a table. 1 for ID, and one for link. Make ID primary, auto increment and link varchar or text. Then make a column hits as int as well. Query the database to retrieve hits, store it in a variable, add 1, then UPDATE table SET `hits`=$hits WHERE id=1 or something similar to that.
Logged

Personal site: http://matt-shaffer.com
Currently being eaten alive by school and attempting to make a half decent game.

Adios. Contact info is in profile. Might want to email me any IM details first, or I won't add you.
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #2 on: September 16, 2008, 07:48:09 AM »

Wait ima have a go now if I can do it with a current script I already have. I'll report back in about 1-2 hours
Heres what I got so far...

Code:
$URL = $_GET['link'];

$getStats = mysql_query("SELECT * FROM `Downloads` WHERE `URL` = '" . $URL . "' && `Title` = '" . $FileName . "'") or die(mysql_error());

 

if( mysql_num_rows( $getStats ) == 0 )

{

    $select = mysql_query("INSERT INTO `Downloads` (`URL`, `Title`, `Ext`, `Hits`) VALUES ('" . $URL . "', '" . $FileName . "', '" . $ext . "', '1')") or die(mysql_error());

}

else

{

    $select = mysql_query("UPDATE `Downloads` SET `Hits` = `Hits`+1");

}

What I need to do now is get it to do that per UNIQUE visitor though.
« Last Edit: September 16, 2008, 08:52:40 AM by inp o҉rtb » Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Offline Offline

Posts: 15633


experimental theologian


WWW
« Reply #3 on: September 16, 2008, 08:09:06 AM »

Then you need to decide what "unique" means to you, and how you intend to determine this uniqueness.
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #4 on: September 16, 2008, 08:13:23 AM »

Well basically it only counts/adds 1 if the user hasnt accessed that page before or atleast in the past 6 hours.

Can you help me implement that?
Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Offline Offline

Posts: 15633


experimental theologian


WWW
« Reply #5 on: September 16, 2008, 08:19:00 AM »

I already did. You need to think a bit more about my hint before you could implement such a system or ask someone to implement it for you. It's quite basic, don't you think?
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #6 on: September 16, 2008, 08:20:20 AM »

Call me stupid.. but im lost  huh lol
Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
thefluffball
Knock. Knock.
Loyal 110MB Member
*******
Offline Offline

Posts: 2314


I came, I saw, I strutted.


WWW
« Reply #7 on: September 16, 2008, 08:28:23 AM »

Your options are cookies or IP's. rolleyes
Logged

iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #8 on: September 16, 2008, 08:34:37 AM »

Ok I think the cookie method would be the best approach. I want it to last about 6 hours.

How can I do this with my current coding?
Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Offline Offline

Posts: 15633


experimental theologian


WWW
« Reply #9 on: September 16, 2008, 08:35:07 AM »

Or user agents, among other fields. And any combination would work.

Add a "uniqueness tester" function that decides if a hit is unique, and log the hit only if it is?
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #10 on: September 16, 2008, 08:39:03 AM »

Or user agents, among other fields. And any combination would work.

Add a "uniqueness tester" function that decides if a hit is unique, and log the hit only if it is?
How do I do a uniqueness tester? I dont know crap about Cookies, Just some php and mysql, thats why I came here to get help from you guys.
Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Offline Offline

Posts: 15633


experimental theologian


WWW
« Reply #11 on: September 16, 2008, 08:50:28 AM »

This is where you open up your browser to Google, type your question into the box, and browse. I know you haven't searched, because there are thousands of pages on these very elementary topics. If you don't know crap about cookies, it's about time you learned about them.

Let's face it; you asked for help on a subject that you claimed to have almost figured out. Instead, you're posting like you want people to make your complete application for you. That, combined with the fact that your sites aren't even hosted here, means you should probably do a bit more of your own homework.

As you must know, we have been quite tolerant of your postings. Do your part, and it'll all be good.
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #12 on: September 16, 2008, 10:28:35 AM »

ok I took your advice and went off to learn about cookies, I got the basics done and i've figured out how I can do with a test cookie. But I cant get it to name cookies from $Href

Code:
setcookie($Href, "The Buzz Limit Count", time()+3600);  /* expire in 1 hour */

if(isset($_COOKIE[$Href]))
{
$last = $_COOKIE[$Href];
echo "Welcome back!";
}
else
{
echo "Welcome to our site!";
}

What am I doing wrong?

Also I found an massive error while doing testing with this,
When using different links on the link= bit, for some reason it adds counts to the other items aswell as the one its on. Have I done something wrong in the code?
Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
Myles Grey
Full-Time Programmer
Super Authority member
******
Offline Offline

Posts: 1863


Programmer's Delight Release - 90%


WWW
« Reply #13 on: September 16, 2008, 10:33:58 AM »

What's the value of $Href? Where's the rest of the script?
Logged

IE has the best Quirks
Almost every site you see runs on Quirks, not standards




Remember to mark your topic as [resolved]
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #14 on: September 16, 2008, 10:37:13 AM »

What's the value of $Href? Where's the rest of the script?
The $Href varies depending on what the link= is (check the link on the first post if you dont get what link= means)

Thats the code that does the cookies, and i've put the code for the counter in the posts above? What else do you need?

Looks like mediafire deleted my the link, input your own link there (preferably mp3) to see the page fully functional. (its a pretty cool script dont ya think)
« Last Edit: September 16, 2008, 10:42:05 AM by iM1 » Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
Myles Grey
Full-Time Programmer
Super Authority member
******
Offline Offline

Posts: 1863


Programmer's Delight Release - 90%


WWW
« Reply #15 on: September 16, 2008, 10:52:28 AM »

Well on your previous code you have this:

Code:
$URL = $_GET['link'];

Do you actually set $Href in the script?
Logged

IE has the best Quirks
Almost every site you see runs on Quirks, not standards




Remember to mark your topic as [resolved]
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #16 on: September 16, 2008, 10:58:11 AM »

yeah $Href has been set literally two lines before the set cookie line.is it because that hasn't been set properly or could it be I coded it wrong?
Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Offline Offline

Posts: 15633


experimental theologian


WWW
« Reply #17 on: September 16, 2008, 11:00:47 AM »

I believe Myles Grey is asking for your whole script; you might not want to keep people guessing about what's in your script wink
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
iM1
Authority Member
****
Offline Offline

Posts: 890


Why drink and drive when you can smoke and fly...


WWW
« Reply #18 on: September 17, 2008, 06:52:38 AM »

As you can see its a gets the link from mediafire, I cant post the whole script because otherwise my competitors are gonna steal the script (Right now im one ahead with that).

Before we continue with the can we go back to the counter, I found why it keeps adding hits to other pages aswell...

Code:
    $select = mysql_query("UPDATE `Downloads` SET `Hits` = `Hits`+1");
Its adding 1 to every item in the table not just the one the one that its supposed to.
I tried this to see if it fixes this problem...

Code:
    $select = mysql_query("UPDATE `Downloads`WHERE `URL` = '" . $URL . " SET `Hits` = `Hits`+1");
But then it didnt work at all  huh
Can anyone tell me what i've done wrong?
Logged

My site is worth
My Sites:
iM1 MUSIC // DesiDrop - Music Blogs
Satize.com - MP3 Search Engine NEW V2!
Myles Grey
Full-Time Programmer
Super Authority member
******
Offline Offline

Posts: 1863


Programmer's Delight Release - 90%


WWW
« Reply #19 on: September 17, 2008, 11:41:49 AM »

Try this:

Code:
$select = mysql_query("UPDATE `Downloads` SET `Hits` = `Hits`+1 WHERE `URL` = '" . $URL . "'");
Logged

IE has the best Quirks
Almost every site you see runs on Quirks, not standards




Remember to mark your topic as [resolved]
Pages: [1]   Go Up
Send this topic | Print
Jump to: