0

I have install a plugin to get channels. And that was i have used in template

{exp:getchannels}
{channel_name}
{/exp:getchannels}

From this I got the result i.e. list of channels. thats ok. working good. and then I need to execute a query like this

{exp:query sql="Select CONCAT('field_id_',field_id) 'field_id', field_name, BASE64_DECODE(field_settings) 'field_settings', field_label
     from exp_channel_fields f join exp_channels c on c.field_group = f.group_id where c.channel_name = 'programme' order by field_order"}
     <br/>{field_name}<br/>
{/exp:query}

from this I got the result of particular channel that is "Programme"

Now my query is that, I would like to use that query EXP inside the getchannel EXP, like below mentioned

{exp:getchannels}
{channel_name}
{exp:query sql="Select CONCAT('field_id_',field_id) 'field_id', field_name, BASE64_DECODE(field_settings) 'field_settings', field_label
     from exp_channel_fields f join exp_channels c on c.field_group = f.group_id where c.channel_name = '{channel_name}' order by field_order"}
     <br/>{field_name}<br/>
{/exp:query}
{/exp:getchannels}

Now problem is that, that query EXP returns blank when i execute that inside getchannel EXP. Here I would like to get the fields of each channel what channels are getting by getchannel EXP, yes same like FOREACH LOOP.

If i echo this query and execute that inside PHPMYADMIN it returns result exactly what i want.

I think there is something wrong with that. Don't getting the idea whats wrong in that. Can Anybody help me to solve that.? I stuck at this point.

Thanks in Advance.

1

Your issue is you cant use php inside the query tag sql. If you dont believe me, look at the source code for query module. From memory its in system/module/query. Remove this:

BASE64_DECODE(field_settings) 'field_settings', field_label

Now this works:

{exp:query sql="Select CONCAT('field_id_',field_id) 'field_id', field_name, c.channel_name {!--BASE64_DECODE(field_settings) 'field_settings', field_label--} from exp_channel_fields f join exp_channels c on c.field_group = f.group_id order by c.channel_name asc, f.field_order asc"} {channel_name}
{field_id}, {field_name}
{/exp:query}

But i see you want to group by channel name, so wrap it with your {exp:getchannels} tag like you did in your example (sorry, using my ipad...takes too long to show code). That should work.

Update: If exp:getchannels is a plugin it wont work. Modules get parsed before plugins parse order. So to change to

{exp:getchannels parse="inward"}

However, you still need to decode the field settings, so your best solution is to create a plugin to run the query, then loop through the output and decode the field settings row.

You can also run queries here. And check db here

| improve this answer | |
  • Hey dadonbike, thanks sir.. somehow this being helpful to me.. – jt. Sep 2 '13 at 8:06
  • No problems. Also, if this question is resolved please mark it as answered so others can benefit from your question – Lloyd Hill Sep 2 '13 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.