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.

sql query for field_id to field_id_n

August 24, 2008 12:44pm

Subscribe [1]
  • #1 / Aug 24, 2008 12:44pm

    Mike Essl

    8 posts

    Hello,

    I’m trying to return the sum of the contents of a custom field. I know the below code is not supposed to work, but does…

    Is the only link between these two tables the field_id=“n” and field_id_n ?

    AND, is there a way to do the below in a single query? I suspect a join is needed in there, but again, me and SQL just started being friendly.

    {exp:query sql="SELECT field_id AS get_the_id FROM exp_weblog_fields WHERE field_name='12ozcans'"}
    
    {exp:query sql="SELECT SUM(field_id_{get_the_id}) AS can_total FROM exp_weblog_data"}
    
    {can_total}
    
    {/exp:query}
    
    {/exp:query}

    Any help would be appreciated. Eventually I want to pass in the custom field name dynamically.

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

ExpressionEngine News!

#eecms, #events, #releases