2

I am using grid type field for express engine channel and i want to show result based to row_id and it was working when i have entered row_ids but it is not working when row_id are not there.

for eg. I have created a channel named as 'XYZ' and having following channel fields there :

1) user_type : text 

2) profile : grid

       a) first_name : text 

       b) last_name :  text

       c) user_name : text 

       d) age : text

Now i want to show user listing for a entry and i am getting row_id for grid from custom query in code. i have used following code :

.............

//here we are getting row_ids from custom query as

// if condition here
<?php  $rowsId="10|11|12"; ?>

// else condition  (set $rowsId value as -1  in case when we are not getting row_id from custom query)

<?php $rowsId = "-1" ; ?> 

..............

{exp:channel:entries channel="xyz" entry_id=1}
    {profile row_id="<?php echo $rowsId; ?>"}
        {profile:first_name}<br/>
        {profile:last_name}<br/>
        {profile:user_name}<br/>
        {profile:age}<hr>
    {/profile}
{/exp:channel:entries}

But the code

{profile row_id="<?php echo $rowsId; ?>"}

it is working in case of <?php $rowsId="10|11|12"; ?>

but it is not working in case of <?php $rowsId = "-1"; ?>

It should not give us result set in that case (should be empty) but It shows one row in result set and i have also tried '$rowsId' value as 0 instead of -1 but it is also not working.

Please help me what is missing/wrong here or give me a solution for the same.

2 Answers 2

1

Unfortunately this is bug in EE grid field. If you are passing invalid parameter for row_id="ABC@#4" it will still show first row from grid.
You can check $rowsId variable and set condition accordingly.

<?php
If ($rowsId == '-1') {
    echo "No result to show";
} else{ ?>
    {profile row_id="<?php echo $rowsId; ?>"}
        {profile:first_name}<br/>
        {profile:last_name}<br/>
        {profile:user_name}<br/>
        {profile:age}<hr>
   {/profile}
<?php } ?>
2

If you are using php in this way, you could just not show the output if it is set to -1

{exp:channel:entries channel="xyz" entry_id=1}
  <?php if ($rowsId != -1) {?>
    {profile row_id="<?php echo $rowsId; ?>"}
        {profile:first_name}<br/>
        {profile:last_name}<br/>
        {profile:user_name}<br/>
        {profile:age}<hr>
    {/profile}
   <?php } ?>
{/exp:channel:entries}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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