skip to Main Content

I am not able to return the property status using the ternary operator

this is my code

<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
                        <div class="form-group">
                                <label for="imo_status">STATUS DO IMÓVEL</label>
                                <div class="form-line">
                                                
                                    <select class="form-control" id="imo_status" name="imo_status">
                                        <option value="">Selecione o Status</option>
                                        <option <?= (isset($imo_status) ? $imo_status : set_value('imo_status')) == '1' ? 'selected' : '' ?> value="Ativo">Ativo</option>
                                        <option <?= (isset($imo_status) ? $imo_status : set_value('imo_status')) == '0' ? 'selected' : '' ?> value="Inativo">Inativo</option>
                                    </select>

                                </div>
                            </div>
                        </div>
                    </div>

Here it should return the option 1 = active

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I solved this

    <select class="form-control" id="imo_status" name="imo_status">
                                            <option value="1"<?=$properties['imo_status'] == '1' ? ' selected="selected"' : '';?>>Ativo</option>
                                            <option value="0"<?=$properties['imo_status'] == '0' ? ' selected="selected"' : '';?>>Inativo</option>
                                        </select>
    

  2. I don’t know what PHP version you are using. But the inline if with character x ? y : z cannot be use twice without bracket. Try this one:

    <option <?= isset($imo_status) ? $imo_status : (set_value('imo_status') == '1' ? "selected" : "")  ?> >Active</option>
    

    Editted

    Sorry i read the code wrongly. Actually you need to see whether the method set_value() has return any value or not and what value they set to.

    Try debug with print_r($imo_status) and print_r(set_value('imo_status')) to see the output.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search