Home > front end >  get data in my dropdown btn does not work
get data in my dropdown btn does not work

Time:10-17

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

this is my code

<div >
                        <div >
                                <label for="imo_status">STATUS DO IMÓVEL</label>
                                <div >
                                                
                                    <select  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

CodePudding user response:

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.

CodePudding user response:

I solved this

<select  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>
  • Related