How many times an image has been viewed using php & mysql

How can I write a code to store the number of times an image or a page has been viewed using php & mysql. The page  is only one file  "index.php". Please let me know if you have any questions.

E.g:                       <!--A page {hompage}-->      <!--A page-->     <!--A page-->   <!--A photos been viewed-->

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
gave me

Create a Simple Hit Counter Using PHP and MySQL
Creating a simple counter (MySQL)
as the first two links.
to count the image you need to serve it from PHP too and update in the PHP that serves it

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Are you wanting these figures to display on the website or do you want them so you can see how your site traffic is developing and don't need to be in the public domain?

If the second,

This will give you a very good idea of where traffic is going on your site.

Also there are also scripts that can parser your server log files.
Ray PaseurCommented:
To my amazement, I do not have a teaching example of a hit counter.  It's such a common tool, that I guess I have not seen a question about it.

Here is the logic you need to implement.  Capture $_SERVER["REQUEST_URI"] and store it in a data base table in the column named "uri" -- this is the URL with the GET arguments intact.  On each page load, write this to your data base table.  You might also want to include a DATETIME column in the table.  Name it "whn."

Then you can use a variety of queries to retrieve the information from the table.  Examples include...

SELECT COUNT(*) FROM hitCount -- How many total page loads occurred?
SELECT COUNT(*) FROM hitCount WHERE uri LIKE '%photoid=754' -- How many times was photo #754 viewed?
SELECT whn FROM hitCount WHERE uri LIKE '%journal' ORDER BY whn DESC LIMIT 1 -- What was the last time someone looked at the "journal" page?

I agree about Google Analytics.  It is the lingua franca of traffic monitoring.  

Best to all, ~Ray
xposegrafixAuthor Commented:
Thanks for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.