Web Analytics Made Easy -
StatCounter help with a dynamic dropdown menu? - CodingForum

Announcement

Collapse
No announcement yet.

help with a dynamic dropdown menu?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help with a dynamic dropdown menu?

    Hi,

    I have a function that looks in my database for people's names that have written a story on my website in my edit story form, and selects that found byline in a dropdown box:

    PHP Code:
    <?php $s_id $byline $byline ''?>
      <select class="big" name="byline" size="1"  style="width: 145px" tabindex="1">
        <option value="" <?php echo ($s_id == '' 'selected="selected"' ''); ?>>Byline</option>
            <?php 
                $type_array
    =get_byline_names(); 
                foreach (
    $type_array as $people
               { 
                  print(
    "<option value=\"".$people['section_id']."\"" . ($s_id == $people['section_id'] ? 'selected="selected"' '') . ">".$people['fullname']."</option>\n"); 
               } 
            
    ?>
    </select>
    Now this works readlly well, but how could I change it to say if it can't find a value then automatically make this the selected value (below)? I've just posted the select box code, as I don't think i'd need to do this at the function level.

    PHP Code:
             <option value="0"<? if ($byline == '0') echo ' selected' ?>>No byline name found</option>
    Thanks

  • #2
    Like this maybe

    PHP Code:
    <?php
    $selected
    ='';
    if (
    $byline == '0'
    {
         
    $selected ' selected';
         echo
    '<option value="0"'.$selected.'>No byline name found</option>';
    }
    else
    {
         
    $type_array=get_byline_names(); 
         foreach (
    $type_array as $people
         { 
                  print(
    "<option value=\"".$people['section_id']."\"" . ($s_id ==$people['section_id'] ? 'selected="selected"' '') . ">".$people['fullname']."</option>\n"); 
          }  
    }
    ?>
    You can not say you know how to do something, until you can teach it to someone else.

    Comment


    • #3
      Thanks, but i'd ideally like it available in the same list as the others selected from the function?

      Comment


      • #4
        Not sure i understand what you mean. If you want it all together just take out the else so it renders the rest regardless

        PHP Code:
        <?php $s_id $byline $byline ''?>
          <select class="big" name="byline" size="1"  style="width: 145px" tabindex="1">
            <option value="" <?php echo ($s_id == '' 'selected="selected"' ''); ?>>Byline</option>
                <?php 
               $selected
        ='';
               if (
        $byline == '0'
               {
                    
        $selected ' selected';
                    echo
        '<option value="0"'.$selected.'>No byline name found</option>';
                }
                    
        $type_array=get_byline_names(); 
                    foreach (
        $type_array as $people
                   { 
                      print(
        "<option value=\"".$people['section_id']."\"" . ($s_id == $people['section_id'] ? 'selected="selected"' '') . ">".$people['fullname']."</option>\n"); 
                   } 
                
        ?>
        </select>
        You can not say you know how to do something, until you can teach it to someone else.

        Comment

        Working...
        X