Author |
Message |
steve_lemaster
Worker


Joined: Dec 26, 2006
Posts: 178
|
Posted:
Thu Jul 12, 2007 11:38 am |
|
Is it possible to place a hit counter inside a specific block to count hits within it?
I have a YouTube video embedded in a block that I would like to track the amount of times it has been viewed. |
|
|
|
 |
fkelly
Former Moderator in Good Standing

Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY
|
Posted:
Thu Jul 12, 2007 12:06 pm |
|
If you want the counter to be "persistent" and cumulative, I think you'd need to store it in a MYSQL table. I don't know if there is an existing table for you to use, probably best to define your own with an integer field, read the value in it, increment it by one and store it each time the video is accessed.
But yes that logic could be contained in a block. |
|
|
|
 |
steve_lemaster

|
Posted:
Thu Jul 12, 2007 1:36 pm |
|
I figured as much. I am a bit skittish on goofing with my database and was hoping I could place the code within the block. |
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Thu Jul 12, 2007 6:15 pm |
|
steve_lemaster, PHP is not "persistent", so you have to figure out other ways to cache the data. A database or a file are really your only options and my vote would be for database as it is ready made to do exactly this (plus it handles all the record locking for you). |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
fkelly

|
Posted:
Thu Jul 12, 2007 7:01 pm |
|
For what it's worth: if you use a separate (new) database table for this and embed the logic in a new block, the chances of doing damage are minimal. You can even use NSNgroups + the admin screens to make the block only visible to a group that includes only you. I'd also recommend having a PHPmyadmin window open as you develop it so you can see exactly what happens to the tables. And there's my mysql.php hack (search for it) that allows you to capture any database errors.
Of course having a localhost test system to start with is the ne plus ultra. |
|
|
|
 |
steve_lemaster

|
Posted:
Thu Jul 12, 2007 9:57 pm |
|
fkelly wrote: | For what it's worth: if you use a separate (new) database table for this and embed the logic in a new block, the chances of doing damage are minimal. You can even use NSNgroups + the admin screens to make the block only visible to a group that includes only you. I'd also recommend having a PHPmyadmin window open as you develop it so you can see exactly what happens to the tables. And there's my mysql.php hack (search for it) that allows you to capture any database errors.
Of course having a localhost test system to start with is the ne plus ultra. |
Ah! I never thought of that. This seems to be the logical approach.
Just to make sure I am understanding you correctly, you are saying create a separate database for the block in which I am going to place the hit counter in.
Now if I only understood how to write code for MySQL  |
|
|
|
 |
montego

|
Posted:
Fri Jul 13, 2007 5:41 am |
|
steve_lemaster, no, just another table within your existing database. Seriously, just use phpMyAdmin to "Add Table" and you are off and running.... well, ok, so you still have to code it.  |
|
|
|
 |
fkelly

|
Posted:
Fri Jul 13, 2007 6:37 am |
|
Hey! I thought I had a three hour time advantage on you M. but you were here ahead of me anyway. But what M. said Steve. |
|
|
|
 |
evaders99
Former Moderator in Good Standing

Joined: Apr 30, 2004
Posts: 3221
|
Posted:
Fri Jul 13, 2007 8:25 am |
|
You can create a seperate PHP page to track the hits.. and just load the page in a block using an iframe
Of course, this won't track anyone who views it through Youtube's site directly |
_________________ - Only registered users can see links on this board! Get registered or login! -
Need help? Only registered users can see links on this board! Get registered or login! |
|
|
 |
steve_lemaster

|
Posted:
Fri Jul 13, 2007 2:17 pm |
|
Anyone have any idea how to code something like this?
The YouTube clip is using the embedding feature and I don't know if that would be relevant. |
|
|
|
 |
|