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.

how to combine URL segments and custom profile fields

March 13, 2009 9:25pm

Subscribe [2]
  • #1 / Mar 13, 2009 9:25pm

    Kerim Satirli

    52 posts

    Gents (Ladies too),

    while trying out a number of different things in EE, I came across a puzzle I have, so far, been unable to solve:

    Every user in my DB has a number of custom profile fields, one of them being a key, shortname {custom_keycode}.

    I would like to allow users to view a certain template (named ‘dump’) if the key is present, even if they are not present e.g:

    http://www.domain.com/tools/c89a1852a0df083485c997e0d148ccb73a2a97ff/dump/

    legend:

    ‘tools’ is a template group
    ‘c89a1852a0df083485c997e0d148ccb73a2a97ff’ is the user’s custom_keycode
    ‘dump’ is the actual template

    the ‘dump’ template should carry out an action (packing up, sending file to user) when the key is present

    How do I tell EE and the ‘dump’ template to loop through all custom_keycode fields and check to see if the presented key is actually listed in the database?

    This would be easy if the user would be logged in, but I want it to work without requiring the user to be logged in.

    Any thoughts or pointers are greatly welcome!

  • #2 / Mar 13, 2009 10:24pm

    e-man

    1816 posts

    How do I tell EE and the ‘dump’ template to loop through all custom_keycode fields and check to see if the presented key is actually listed in the database?
    Any thoughts or pointers are greatly welcome!

    You’ll have to change that URL if you want to use the key as a segment variable.

    http://www.domain.com/tools/dump/c89a1852a0df083485c997e0d148ccb73a2a97ff/

    Probably the easiest way to do this is via a custom query and then check if you have no result.

    {exp:query sql="SELECT field_id_2 FROM exp_weblog_data where field_id_2 ='{segment_3}'"}
    {if no_results}
    no key found
    {if:else}
    key found…
    {/if}
    {/exp:query}

    field-id_2 is only used for illustration purposes, you’ll have to check the id of your specific custom field.

  • #3 / Mar 14, 2009 6:17am

    Kerim Satirli

    52 posts

    thank you for the very fast reply!

    I did some testing and I found that the query has to contain “m_field_id_1” from the “exp_member_data” table (since it is a custom profile field).

    When I enter the query as follows in phpMyAdmin:

    SELECT `m_field_id_1` FROM `exp_member_data` where `m_field_id_1` = 'c89a1852a0df083485c997e0d148ccb73a2a97ff'

    it displays one result, just as expected. However, when I move this query into an EE tag, like so:

    {exp:query sql="SELECT `m_field_id_1` FROM `exp_member_data` where `m_field_id_1` = '{segment_3}'"}
    {if no_results}
    no key found
    {if:else}
    key found…
    {/if}
    {/exp:query}

    it displays nothing at all, no matter if segment_3 is an existing key or something completely different.

    I have the Query module installed and am able to run the queries that are listed in the docs without any problem. Heck, even PMA shows the data I need.

    What am I doing wrong?

    [EDIT]

    Oh and yes, I changed the call so that the template name appears before the keyname

    [EDIT 2]

    I just enabled SQL debugging and one of the queries was indeed the one I have in the templates and it is listed correctly (meaning: I can copy/paste it to PMA, execute and get the result I am looking for), yet the template does not display anything.

    Very weird.

    [EDIT 3]

    {exp:query sql="SELECT m_field_id_1 FROM exp_member_data where m_field_id_1 = '{segment_3}'"}
    
    {m_field_id_1}
    
    {if no_results}
    No results!
    {/if}

    solves the problem for me. Thanks again for the pointers!

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

ExpressionEngine News!

#eecms, #events, #releases