lundi 18 novembre 2019

How to use simplified select box IF statements PHP

I have a trip status page and I want to output the status of the trip.

I'm storing numeric values in the Database on creation of the trip.

Status values:

  • 0 = On Time
  • 1 = On Hold
  • 2 = Delayed
  • 3 = Completed
  • 4 = Canceled

This is my current working IF Statement: Just want to simplify it

<select name="status">
    <option value="" selected>
        @if($destination->status == 0)
            On Time
        @elseif($destination->status == 1)
            On Hold
        @elseif($destination->status == 2)
             Delayed
        @elseif($destination->status == 3)
            Completed
        @elseif($destination->status == 4)
            Canceled
        @endif
     </option>
</select>

For simple YES or NO IF Statements I can do this:

$destination->private = 0 for No & 1 for Yes

<option value="" selected></option>

How can I take the Simple Yes or No Logic and apply it to my larger select box If Statement?

Aucun commentaire:

Enregistrer un commentaire