mercredi 23 mars 2016

PHP and Radio Buttons

Is there a better way or shorter way to do this ? I am trying to check a radio button based on the data retrieved from a database field ??

<?php

          $ck2 = $objResult["MOV"];

          if ($ck2 == "Y") {

          echo "<input id='x1' type='radio' name='movie' value='Y' checked='checked'><label for=''x1'>Yes</label>";
          echo "</div>";
          echo "<div>";
          echo "<input id='x2' type='radio' name='movie' value='N'><label for=''x2'>No</label>";

          } elseif ($ck2 == "N") {

          echo "<input id='x1' type='radio' name='movie' value='Y'><label for=''x1'>Yes</label>";
          echo "</div>";
          echo "<div>";
          echo "<input id='x2' type='radio' name='movie' value='N' checked='checked'><label for=''x2'>No</label>";

          } else {

          echo "<input id='x1' type='radio' name='movie' value='Y'><label for=''x1'>Yes</label>";
          echo "</div>";
          echo "<div>";
          echo "<input id='x2' type='radio' name='movie' value='N'><label for=''x2'>No</label>";

          }

          ?>

Aucun commentaire:

Enregistrer un commentaire