We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 813 ☆ A M B ☆
    • 326 Posts
    I’m trying to use Page Hit Counter and Page Hit Counter Results to display a "Most Viewed Pages" sidebar on my site. It actually is working, but the problem is, the same page is showing up multiple times in the results.

    In my template, I’m calling the chunk {{populararticles}}, which looks like this:

    <h3>Most Viewed Pages</h3>
    <ul>
    [!PHCResults? &excludeIDs=`1,2,3,4` &limit=`6` &table_prefix=`modx_` &tpl=`populararticlesitem`!]
    </ul>

    The template chunk (populararticlesitem) looks like this:

    <li><a href="[+phc.pageID+]">[+phc.title+]</a></li>

    Any ideas? What’s confusing to me is the fact that it’s working, but not correctly.
      • 4310
      • 2,310 Posts
      Sounds like the PHC is recording multiple entries for each page id in the modx_page_hit_counter DB table.
      My results snippet doesn’t check or care if there are multiple rows.
      Perhaps you could check via PHPMyAdmin and confirm?
        • 813 ☆ A M B ☆
        • 326 Posts
        I’ll take a look. I’m not a database expert, but I’ll see what I can find. Is there anything specific I should be looking for?
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          Bunk -- where are page hits stored, anyway?
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            {prefix}page_hit_counter  wink

            I do try to use self-explanatory names laugh

            It uses ON DUPLICATE KEY to update the count instead of inserting a new record if the docID is the same; the page_id field is a unique key. Could this misbehave depending on the version of MySQL?
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 4310
              • 2,310 Posts
              This is what it should look like, i.e no duplicate page_id values.
                • 9207 ☆ A M B ☆
                • 2,475 Posts
                {prefix}page_hit_counter

                Ah... I guess I don’t have that installed... I thought I was going senile.
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  You have to install the module and run it, and it will tell you the table doesn’t exist; there’s a button to create the table.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 813 ☆ A M B ☆
                    • 326 Posts
                    Mine looks more like the attached image (lots of repeating page numbers). Again, not a MySQL expert -- how do I prevent this from happening? I am using PHP5. Could this be part of the problem? That it doesn’t work right with ON DUPLICATE KEY? Can this be fixed?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Check the table and make sure that the page_id is still set as a UNIQUE KEY.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org