ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Count total entires assigned to logged in author

December 04, 2010 3:14pm

Subscribe [4]
  • #1 / Dec 04, 2010 3:14pm

    Tony Geer

    253 posts

    Im trying to figure out the best way to display the total number of entries published by the logged in author, as well as the number of entries that have a particular custom field with a certain value. I know I’ll have to use a query to do this, but I’m hopelessly lost in trying to figure it out.

    Any help would be appreciated.

  • #2 / Dec 04, 2010 3:21pm

    David Dexter

    88 posts

    I’m assuming you want to tackle those to goals with separate queries. What version of EE are you using?

    Thanks,
    David

  • #3 / Dec 04, 2010 3:22pm

    Tony Geer

    253 posts

    Yes, so I guess it’s basically two questions in one, sorry for the mixup!

    Using EE2.

  • #4 / Dec 04, 2010 4:37pm

    Tony Geer

    253 posts

    Okay so David was able to write a quick plugin called Countee that shows the entry count for logged in users, which was pretty awesome of him!

    I still need to be able to show number of entries that have a particular custom field with a certain value.

  • #5 / Dec 04, 2010 5:05pm

    Brooks Seymore

    106 posts

    This is completely untested and close to a guess but I’m thinking a query like “SELECT * FROM exp_channel_data WHERE field_id_77 = ‘Blue’” which would get part of what you need and the {total_results} tag would bring it on home.

    If that doesn’t work, check out the Tizag tutorial on using the COUNT function in MySQL

    http://www.tizag.com/mysqlTutorial/mysqlcount.php

  • #6 / Dec 04, 2010 5:15pm

    Wouter Vervloet

    758 posts

    I think that if you ask David real nicely and give him some lovin’ he would be able to alter Countee a little to also be able to count entries with a certain value.

    My implementation would be something like this:

    // Count member total_entries
    {ecp:countee member='{logged_in_member_id}'}
    
    // Count entries with a certain value
    {exp:countee custom_field_name='Blue'}

    This way you could even count the number of entries belonging to a certain member AND containing a certain value.

    {exp:countee member='{logged_in_member_id}' custom_field_name='Blue'}

    Of course you could extend its functionality even more and include all the parameters also available for the channel module, but that would seriously impact the speed and query load on the page.

    If David is too busy with pleasing all the e-commerce peepz to implement this, I would be happy to take a look at it (if he doesn’t mind).

    And Brooks query would do the trick, but with a little change it would be more efficient:

    {exp:query sql="SELECT COUNT(*) AS entry_count FROM exp_channel_data WHERE field_id_77 = ‘Blue’"}
      {entry_count}
    {/exp:query}

    This would return only 1 row with the needed value instead of the entire set of entries matching the query.

    Greetz,
    Wouter

  • #7 / Dec 04, 2010 5:24pm

    David Dexter

    88 posts

    Hey Wouter….

    I like it. I think I’ll add the parameter syntax as => customer_field:color=“blue” that way you can define the field name and value.

    Best,
    David

  • #8 / Dec 04, 2010 5:36pm

    Wouter Vervloet

    758 posts

    Hi David,

    The ‘customer_field’ part wouldn’t be necessary per se, as you can loop through all the parameters that are set using:

    $search_params = array();
    
    foreach ($this->EE->TMPL->tagparams as $param => $value)
    {
      if($param == 'member' || $this->field_exists($param) === true)
      {
        $search_params[$param] = $value;
      }
    
      // Insert magic and fairy dust here..
    }

    You can then check them against the exp_channel_fields table (which you will have to do anyway) to see if the exists (filtering out the member-parameter out first, of course).

    Greetz,
    Wouter

  • #9 / Dec 04, 2010 7:13pm

    David Dexter

    88 posts

    I uploaded a new version to GetEE.com with an additional search:custom_field=“something” parameter.

    http://getee.com

    Hope that does what you need.

    Best,
    David

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases