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.

Select query

April 09, 2012 8:01pm

Subscribe [2]
  • #1 / Apr 09, 2012 8:01pm

    zizther

    228 posts

    Hi

    I’m looking to do a select query which will incoporate multiple tables and multiple where clauses. Is this possible and easy to do. I am doing it through the EE query module.

    Basically i need to display entries from a channel made by a certain member group who have selected their entry to be public (they do this by selecting ‘yes’ in a custom field)

    I need to get:

    * entry_date from exp_channel_titles
    * field_id_15, field_id_16 from exp_channel_data
    * where group_id = 6 AND field_id_16 = yes

    I know the above is not accurate and may need to invlove other tables.

    If this is best done by a query or another method i am happy to hear.
    If a query is the best way could someone put together the query?

    Thanks

  • #2 / Apr 10, 2012 3:25pm

    Shane Eckert

    7174 posts

    Hey zizther,

    I am going to move this over to the Community Help Forum to see if the community can help you with the query. You might also post in the development and programming forum as this is perfect for them.

    Cheers,

  • #3 / Apr 10, 2012 3:30pm

    zizther

    228 posts

    Thanks Shane,

    Your right, sorry!
    Have also posted in the development and programming forum.

  • #4 / Apr 10, 2012 3:57pm

    glenndavisgroup

    436 posts

    Hi zizther,

    Try the following:

    {exp:query limit="10" 
    sql="SELECT cd.channel_id,ct.title,cd.field_id_16 as public
         FROM exp_channels c, exp_channel_data cd, exp_channel_titles ct, exp_members m 
         where c.channel_name = 'YourChannelName' 
           and cd.channel_id = c.channel_id 
       and ct.channel_id = cd.channel_id 
       and ct.entry_id = cd.entry_id 
       and m.member_id = ct.author_id
              and m.group_id = '6'
       and ct.status = 'open'
              and cd.field_id_16 = 'yes'
         order by ct.title asc"}
    
    {channel_id}
    
    {title}
    
    {public}
    
    <hr>
    
    {/exp:query}

    See if that works for you.

    [update]
    Change the ‘YourChannelName’ to your channel name.

    Mike

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

ExpressionEngine News!

#eecms, #events, #releases