We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to use {exp:query} results in {exp:channel} parameter?

How Do I?

shbchk's avatar
shbchk
12 posts
4 years ago
shbchk's avatar shbchk

Since i can not retrieve {parents} from grid field, i am trying to find simplest workaround.

This works great:

{exp:channel:entries channel='channel-one' entry_id='        
        <?php
            $servername = 'blabla';
            $username = 'blabla';
            $password = 'blabla';
            $dbname = 'blabla';

            // Create connection
            $db = mysqli_connect($servername, $username, $password, $dbname);
            // Check connection
            if (!$db) {
            die("Connection failed: " . mysqli_connect_error());
            }
            
            $url_pieces = explode("/", $_SERVER['REQUEST_URI']);

            $sql = 'SELECT parent_id FROM exp_relationships WHERE child_id = '.$url_pieces[2].'';
            $result = mysqli_query($db, $sql);

            while($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
                echo $row['0']."|";
            }
        ?>
    ' disable='categories|member_data|pagination|category_fields'}

This works great also and produces little more total_queries:

{exp:channel:entries channel='channel-one' entry_id='        
            <?php
                $pieces = explode("/", $_SERVER['REQUEST_URI']);
                $sql = 'SELECT parent_id FROM exp_relationships WHERE child_id = '.$pieces[2].'';
                
                $query = ee()->db->query($sql); 
    
                if ($query->num_rows() > 0)
                {
                    foreach($query->result_array() as $row)
                    {
                        echo $row['parent_id']."|";
                    }
                }            
            ?>
    ' disable='categories|member_data|pagination|category_fields'}

But i can not get same result when i’m trying to use {exp:query}, it shows me nothing or error.

Here is what i’ve tried:

{parents_ids} Template Partial content:

{exp:query sql="SELECT parent_id FROM exp_relationships WHERE child_id = '{last_segment}'" backspace="1"}{parent_id}|{/exp:query}

Tempate code:

{exp:channel:entries channel='channel-one' entry_id='{parents_ids}' disable='categories|member_data|pagination|category_fields'}

This returns nothing.

Is there anyway to do what i am trying to do without php in templates?

(ExpressionEngine® CMS 5.3.2, PHP 7.3.15)

       
Tom Jaeger's avatar
Tom Jaeger
228 posts
4 years ago
Tom Jaeger's avatar Tom Jaeger

We just pushed a fix for this to the repo and it will be in the next release.

https://github.com/ExpressionEngine/ExpressionEngine/issues/432

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.