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 by category and custom field

January 11, 2012 5:13pm

Subscribe [2]
  • #1 / Jan 11, 2012 5:13pm

    Happy Content

    56 posts

    I have a list of staff members (about 80 in total)
    Each staff member is assigned to a state (california, texas etc) - via a category
    Each staff member has an area of expertise (property, manufacturing etc) - via input of a custom field

    I need to be able to create a link that when clicked on returns only staff of a specific state and expertise.

    Eg. John Smith - Texas, manufacturing

    I assume the only way to do this is with an SQL query. Something like

    SELECT Person WHERE STATE=Texas and CUSTOM_FIELD_NAME=manufacturing

    Is anyone able to help me construct such a query? Or point me in the right direction of another method to get this done?

     

  • #2 / Jan 12, 2012 7:10pm

    e-man

    1816 posts

    I have a list of staff members (about 80 in total)
    Each staff member is assigned to a state (california, texas etc) - via a category
    Each staff member has an area of expertise (property, manufacturing etc) - via input of a custom field

    I need to be able to create a link that when clicked on returns only staff of a specific state and expertise.

    Eg. John Smith - Texas, manufacturing

    I assume the only way to do this is with an SQL query. Something like

    SELECT Person WHERE STATE=Texas and CUSTOM_FIELD_NAME=manufacturing

    Is anyone able to help me construct such a query? Or point me in the right direction of another method to get this done?

    You could easily do this with url segments http://ellislab.com/expressionengine/user-guide/templates/globals/url_segments.html and a dedicated template.
    When using categories in url segments I always use Low’s seg2cat http://gotolow.com/addons/low-seg2cat 
    Say your link is “/staff/texas/manufacturing” then in your staff template you could use the following entries loop (this assumes seg2cat is installed):

    {exp:channel:entries channel="your_channel" disable="member_data|pagination" category="{segment_1_category_id}" search:name_of_custom_field_here="manufacturing"}
    list data
    {/exp:channel:entries}

    Makes sense?

  • #3 / Jan 12, 2012 10:42pm

    Happy Content

    56 posts

    Good suggestion. I’ve done and you said and it works well. Thanks.

  • #4 / Jan 13, 2012 5:50am

    e-man

    1816 posts

    Glad it did. One addendum though, the search parameter should be:

    search:name_of_custom_field_here="{segment_2}"}

    to make it truly dynamic, but I guess you figured that out already.

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

ExpressionEngine News!

#eecms, #events, #releases