简体   繁体   中英

How to give id to auto generated element automatically

I want to make a dropdownlist that contains something from my database, all going well until I need to give each of the option unique id

 <div class="div3" >
    <select id="input2" class="drop" name="a" required>
      <option value="" selected disabled>a</option>
      <?php while ($row1 = mysqli_fetch_array($result)) :; ?>
        <option class="option"><?php echo $row1[0]; ?></option>
      <?php endwhile; ?>
    </select>
  </div>

Put an id unique value in option tag, and order you code for make an array with html tag, for example if $row1[0] = uniqueid and $row1[1] = name

<?php while ($row1 = mysqli_fetch_array($result)){?>
  <option id="<?php echo $row1[0]; ?>" class="option"><?php echo $row1[1]; ?></option>
  <?php }?>

  

Best Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM