greetings,
from the post here: http://ellislab.com/forums/viewthread/40382/
Derek says that vanilla segment if conditionals should be processed before the nested exp:query
i.e
{if segment_3 != "this-cool-segment" }
{exp:query sql="SELECT something FROM table WHERE thing = '{segment_3}’”}
{something}
{exp:query}
{/if}
But I am not seeing the same results. I am getting an error due to the second query trying to run.
The error is the table doesn’t exist - which is correct, but only possible if the surrounding conditional is being ignored as i explain below.
I am on EE 1.6.3
Here is a simplified template:
{if "{segment_3}” == “” OR “{segment_3}” == “ALL”}
{exp:query sql="SELECT COUNT(baby_name_id) AS bntotal FROM baby_names2 WHERE gender = 'M' AND active = 1"}
{bntotal}
{/exp:query}
{if:else}
{exp:query sql="SELECT COUNT(bn.baby_name_id) AS bntotal FROM baby_names2 bn JOIN baby_rank_{segment_3} AS br ON bn.baby_name_id = br.baby_name_id WHERE bn.active = 1 AND bn.gender = ‘M’”}
{bntotal}
{/exp:query}
{/if}
the url i am going to is mydomain.com/top_list/Boy
when a state gets added, it becomes segment_3
i.e mydomain.com/top_list/Boy/NY
the second query joins a table whose name is formed from segment_3 - so if there is no segment_3, there is no table for it join, thus throwing the table table does not exist error - which makes perfect sense - the question here is - why is EE trying to execute the second query? - it is as if it is totally ignoring the conditionals.
standing by..