default userpic

Counting occurrences of a custom field

Vote 0 Votes

Hi there, I haven't fully dived into this on the database side of things yet, but wondered if someone might be able to explain it to me as I start doing that.

We are running MT 4.34 Pro, and our client (for accounting/budgeting reasons) needs to be able to count how many entries on their public site are of type A or type B. So we created a new field for "Entries" that is a simple radio button with the two values, and it defaults to one of the values.

So I figured I would just hand write a little PHP page that queries the database to give a running tally of ALL entries, broken down by those of type A and those of type B, giving a % calculation next to each.

Can someone point me to the best place to find our use of this field in the MySQL database itself? I don't need you to write out a SQL query for me, but where is my new, custom field actually stored?

Reported on Movable Type 4.3

2 Replies

| Add a Reply
  • Hi, Neal,

    I'd like to recommend you to use MT's original tag, to display numbers of all published entries.

    http://www.movabletype.org/documentation/appendices/tags/blogentrycount.html

    You can use "include_blogs" modifier to indicate including blogs.

    For example, there are two blogs and their blog's id is 2 and 3 each, then you can get the numbers of all published entries

    <mt:BlogEntryCount include_blogs="all">

    or

    <mt:BlogEntryCount include_blogs="2,3>

    More usage information is available at Japanese MT document.
    http://www.movabletype.jp/documentation/appendices/tags/blogentrycount.html


    Besides that, entry's custom-field data is ordinary placed to "mt_entry_meta" table. So please check this table with your sql client software, such as phpMyAdmin.

    ----------------------------------
    MTJ
    Information of MovableType and MTOS from Japan

    http://www.mt-j.info
    ----------------------------------

  • You can do this with standard template tags, setting and retrieving some variables, and using available modifiers/operators to do a little math and formatting. I've used the more specific <mt:EntriesCount> tag to find the number of entries of each type (returning the number of entries in the context of the <mt:Entries> listings.

    This example assumes that the basenames for your custom fields are "field_a" and "field_b" - just change the <mt:Entries> tags if they are not. It also assumes you have less than 9999 of each type of entry.


    For each entry type, create the context for each, and count how many entries:

    <mt:Entries field:field_a="1" limit="9999">
    <mt:EntriesCount setvar="a_entries">
    </mt:Entries>
    <mt:Entries field:field_b="1" limit="9999">
    <mt:EntriesCount setvar="b_entries">
    </mt:Entries>

    Set a variable for the number of entries in the entire blog:

    <mt:BlogEntryCount setvar="all_entries">
    <mt:Var name="all_entries"><br  />

    Number of A entries (retrieving the variable set earlier):

    <mt:Var name="a_entries"><br />

    Number of B entries:

    <mt:Var name="b_entries"><br />

    Do some math, and work out what fraction of the A is of the total entries (using the variable set earlier), and then multiplying by 100 to get a percentage, and then finally formatting to 2 decimal places.

    <mt:Var name="a_entries" op="/" value="$all_entries" setvar="a_entries"> 
    <mt:Var name="a_entries" op="*" value="100" setvar="a_entries">
    <mt:Var name="a_entries" sprintf="%.02f"> % (to 2 decimal places)
    <br />

    And the same for B entries:

    <mt:Var name="b_entries" op="/" value="$all_entries" setvar="b_entries"> 
    <mt:Var name="b_entries" op="*" value="100" setvar="b_entries">
    <mt:Var name="b_entries" sprintf="%.02f"> % (to 2 decimal places)
    

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

695 2910

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 567

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012