Enum Foreaach

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arggg
    New Member
    • Mar 2008
    • 91

    Enum Foreaach

    I have an enum mysql field with a null value ''. I need that null value to be disabled in the dropdown list however it is showing the html <option> as <option/> Here is the code I have.

    [code=php]
    foreach($enums as $key)
    {
    echo "<option ".$func->iif($key==$res ults['Group'],'selected','') .">".$func->makeSafe($key) ."</option>";
    }[/code]

    I have also tried the following with no success either.
    [code=php]
    foreach($enums as $key)
    {
    if (is_null($key) || !isset($key))
    echo "<option></option>";
    else
    echo "<option ".$func->iif($key===$re sults['Group'],'selected')."> ".$func->makeSafe($key) ."</option>";
    }[/code]

    anyone know why this displays the null option as <option/> and not <option></option>?
  • arggg
    New Member
    • Mar 2008
    • 91

    #2
    I have tried adding slashes to escape the quotes but still no luck.

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      How about:
      [PHP]<?php
      foreach($enums as $key)
      {
      ?>
      <option <?php echo ( $func->iif($key==$res ults['Group'],'selected','') ); ?> >
      <?php echo ( $func->makeSafe($ke y) ); ?> </option>
      }[/PHP]

      Or something like that? Just further separating the html and php?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by arggg
        I have an enum mysql field with a null value ''. I need that null value to be disabled in the dropdown list however it is showing the html <option> as <option/> Here is the code I have.

        [code=php]
        foreach($enums as $key)
        {
        echo "<option ".$func->iif($key==$res ults['Group'],'selected','') .">".$func->makeSafe($key) ."</option>";
        }[/code]

        I have also tried the following with no success either.
        [code=php]
        foreach($enums as $key)
        {
        if (is_null($key) || !isset($key))
        echo "<option></option>";
        else
        echo "<option ".$func->iif($key===$re sults['Group'],'selected')."> ".$func->makeSafe($key) ."</option>";
        }[/code]

        anyone know why this displays the null option as <option/> and not <option></option>?
        I don't understand how this is happening...
        You're not echoing '<option/>' anywhere, so it shouldnt be printed.

        Comment

        • bucabay
          New Member
          • Apr 2007
          • 18

          #5
          Originally posted by arggg
          I have an enum mysql field with a null value ''. I need that null value to be disabled in the dropdown list however it is showing the html <option> as <option/> Here is the code I have.

          [code=php]
          foreach($enums as $key)
          {
          echo "<option ".$func->iif($key==$res ults['Group'],'selected','') .">".$func->makeSafe($key) ."</option>";
          }[/code]

          I have also tried the following with no success either.
          [code=php]
          foreach($enums as $key)
          {
          if (is_null($key) || !isset($key))
          echo "<option></option>";
          else
          echo "<option ".$func->iif($key===$re sults['Group'],'selected')."> ".$func->makeSafe($key) ."</option>";
          }[/code]

          anyone know why this displays the null option as <option/> and not <option></option>?
          How are you viewing the HTML source?
          Some browsers will interpret a <tag></tag> as <tag />.

          [HTML]if (is_null($key) || !isset($key))[/HTML]

          Is useless here. isset($key) will always return true. NULL converts to an empty string with echo() so there is no need to test if its null, then write out the literal <option></option>.

          Comment

          • arggg
            New Member
            • Mar 2008
            • 91

            #6
            I found where the issue was with the <option/> It appears if there is no text between the <option></option> tags it will change the tags to <option/> It must be the browsers or something... Who knows so what I did was if the value = '' then just do <option value=''>[None]</option> to fix this problem.

            Comment

            Working...