Jump to content

Recommended Posts

Hi Guys,

 

Just want to run past an idea I am having, I want to make sure the logic is sound.

 

Basically, I am making a website statistics feature for my Content Management System. I want to create a function that will work out the most visited pages on the website. I currently collect a multitude of data, which is stored in a table in my database. Each time a person loads a page the data is added to the table. Some of that data includes the page id.

 

My plan is call this data from the database and add the data to an array. As the rows of the table are being looped through, the script would check to see if the pageid is already in the array, and increment the count, and if not add it to the array until it has collected all of the logs. The array would then be sorted and the top 10 pages would be shown in a graph on the website.

 

Does that logic make sense? Is there a simpler way of doing it?

 

Any input would be great.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/272451-counting-database-entries/
Share on other sites

Does that logic make sense?

No.

 

Is there a simpler way of doing it?

Yes. Just do a query to do all that work for you. Here is an example that will return the top 10 most visited pages (assuming there is a separate record for each page hit)

SELECT pageID, COUNT(pageID) as hits
FROM stats_table
GROUP BY pageID
ORDER BY hits DESC
LIMIT 10

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.