www.webdeveloper.com
Results 1 to 15 of 15

Thread: Hit counter for each page!

  1. #1
    Join Date
    May 2009
    Posts
    23

    Hit counter for each page!

    Hello everybody,
    Anyone can help me in hit counter? I need get the hit of each page for my side...

    Thanks a lot!

  2. #2
    Join Date
    Jun 2009
    Posts
    131
    Kind of broad..

    Do you need to calculate all hits total? Or itemized hits per page?

  3. #3
    Join Date
    May 2009
    Posts
    23
    Quote Originally Posted by PierceMoore View Post
    Kind of broad..

    Do you need to calculate all hits total? Or itemized hits per page?

    I need both!

  4. #4
    Join Date
    Jun 2009
    Posts
    131
    Sorry for the delay.

    I dislike cross-posting, however I wrote a large amount of code in another thread located here.

    That is the code and table structure that should allow you to count pages individually. In order to extend the code to count all page views, you need only run an sql query that will pull the values from each counter field in the database and add them together.

    Please let me know if this helps!


    Pierce

    This

  5. #5
    Join Date
    May 2009
    Posts
    23

    Thumbs up

    Quote Originally Posted by PierceMoore View Post
    Sorry for the delay.

    I dislike cross-posting, however I wrote a large amount of code in another thread located here.

    That is the code and table structure that should allow you to count pages individually. In order to extend the code to count all page views, you need only run an sql query that will pull the values from each counter field in the database and add them together.

    Please let me know if this helps!


    Pierce

    This

    Thanks Pierce

    Anyway, it is a good idea for me to structure my table. And i done a similar one and it is useful. Thanks

  6. #6
    Join Date
    Jun 2009
    Posts
    131
    Not a problem! So you did get your page counter working?

    Let me know!


    Pierce

  7. #7
    Join Date
    May 2009
    Posts
    23
    Quote Originally Posted by PierceMoore View Post
    Not a problem! So you did get your page counter working?

    Let me know!


    Pierce
    Ya. I can capture the total hits and save it into database. So now i just need to create some report that related to the hits.

    May i ask some question?

  8. #8
    Join Date
    Jun 2009
    Posts
    131
    Excellent! If you were using the code that I wrote earlier, you could generate a report that looks good if you did something like this:

    PHP Code:

    <?php
        $query 
    mysql_query("
                    SELECT `url`,`viewcount`
                    FROM `wd_test`
                "
    ) or die(mysql_error());
                
        while(
    $row mysql_fetch_assoc($query)) {
            echo 
    '<table><tr><td>Page</td><td>View Count</td></tr>';
            foreach(
    $query as $key=>$value) {
                echo 
    "<tr><td>$key</td><td>$value</td></tr>";
            }
            echo 
    '</table>';
        }
    ?>
    That should generate a row for each URL and display the URL and respective view count.

    Sure, ask away!


    Pierce

  9. #9
    Join Date
    May 2009
    Posts
    23
    Quote Originally Posted by PierceMoore View Post
    Excellent! If you were using the code that I wrote earlier, you could generate a report that looks good if you did something like this:

    PHP Code:

    <?php
        $query 
    mysql_query("
                    SELECT `url`,`viewcount`
                    FROM `wd_test`
                "
    ) or die(mysql_error());
                
        while(
    $row mysql_fetch_assoc($query)) {
            echo 
    '<table><tr><td>Page</td><td>View Count</td></tr>';
            foreach(
    $query as $key=>$value) {
                echo 
    "<tr><td>$key</td><td>$value</td></tr>";
            }
            echo 
    '</table>';
        }
    ?>
    That should generate a row for each URL and display the URL and respective view count.

    Sure, ask away!


    Pierce

    Once it can capture the hits for each page, then the report will not be the problem. But i just need to make it more interesting and more powerful, like view by daily, weekly, monthly, or create some statistic about the top 10 of hits.

    My question is are you work as programmer now? How long you in this field?

  10. #10
    Join Date
    Jun 2009
    Posts
    131
    Ah, yes, I completely understand. That would be really cool! That does indeed get more complicated, however, as there are considerably more steps involved. You will likely need to archive the top 10 urls in separate tables for each (daily,weekly,monthly,yearly) and run an sql query at any time to retrieve the top 10 urls at the current moment.

    PHP Code:
    <?php
        $topten 
    mysql_query("
                SELECT `url`,`viewcount`
                FROM `wd_test`
                ORDER BY `viewcount` DESC
                LIMIT 10        
                "
    ) or die(mysql_error());
        while (
    $row mysql_fetch_assoc($topten)) {
            echo 
    '<table><tr><td>URL</td><td>View Count</td></tr>';
            foreach (
    $row as $key=>$value) {
                echo 
    "<tr><td>$key</td><td>$value</td></tr>";
            }
            echo 
    '</table>';
        }
    ?>
    That should grab your top ten results.

    And I do not work specifically as a programmer, I have much to learn, however I am getting my web design company off the ground. I do enjoy PHP, though, that is for sure. I have been doing web design for almost a year now (?). Somewhere around there :-)


    Pierce
    Last edited by PierceMoore; 07-09-2009 at 01:20 AM.

  11. #11
    Join Date
    May 2009
    Posts
    23
    Quote Originally Posted by PierceMoore View Post
    Ah, yes, I completely understand. That would be really cool! That does indeed get more complicated, however, as there are considerably more steps involved. You will likely need to archive the top 10 urls in separate tables for each (daily,weekly,monthly,yearly) and run an sql query at any time to retrieve the top 10 urls at the current moment.

    PHP Code:
    <?php
        $topten 
    mysql_query("
                SELECT `url`,`viewcount`
                FROM `wd_test`
                ORDER BY `viewcount` DESC
                LIMIT 10        
                "
    ) or die(mysql_error());
        while (
    $row mysql_fetch_assoc($topten)) {
            echo 
    '<table><tr><td>URL</td><td>View Count</td></tr>';
            foreach (
    $row as $key=>$value) {
                echo 
    "<tr><td>$key</td><td>$value</td></tr>";
            }
            echo 
    '</table>';
        }
    ?>
    That should grab your top ten results.

    And I do not work specifically as a programmer, I have much to learn, however I am getting my web design company off the ground. I do enjoy PHP, though, that is for sure. I have been doing web design for almost a year now (?). Somewhere around there :-)


    Pierce

    Ya, that is what i want actually. Yes, it will be more complicated when create such statictis report, but i believe that it is possible to be done.

  12. #12
    Join Date
    Jun 2009
    Posts
    131
    It is definitely possible, but much more work than I could spare right now :-P

  13. #13
    Join Date
    May 2009
    Posts
    23
    Quote Originally Posted by PierceMoore View Post
    It is definitely possible, but much more work than I could spare right now :-P

    Ya, it is only complicated but not difficult! Hope i can done asap!

  14. #14
    Join Date
    Jun 2009
    Posts
    131
    Absolutely! I am definitely curious to see what you come up with :-)


    Pierce

  15. #15
    Join Date
    May 2009
    Posts
    23
    Quote Originally Posted by PierceMoore View Post
    Absolutely! I am definitely curious to see what you come up with :-)


    Pierce

    Although it was a little bit complicated, but it has been done!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles