We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37286
    • 160 Posts
    I have a fairly complex query and I'm trying to get a count before I display the data on the page so I can limit the data. However, when I use any of the joins or a groupby, the count returns odd numbers that are not correct. For example, if I only use one of the joins in the query, I get a count of 0, but if I remove the join and add the groupby, I get a count of 1. In both instance there are far more than one result. In case you are wondering, a join and a groupby together returns a result of 0.

    The question is, why is this happening and is there a way around it?
      • 4172
      • 5,888 Posts
      there are several posts about this here in the forums, for example:

      http://forums.modx.com/thread/31886/counting-objects-in-a-collection#dis-post-172434
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37286
        • 160 Posts
        Thanks for the link, I searched all over but didn't stumble across that one. The statement used there didn't work for me very well, but it did lead me to something that worked out great.

                $count= 0;
                if($c->prepare() && $c->stmt->execute()){
                    $count= $c->stmt->rowCount();
                }
        


        The reason the other one didn't work for me was because there were several columns that were concatenated with having clauses to filter the data. Couldn't figure out how to create a count column to contain all that information and still use groupby. This works great though.