forms - PHP - change last looping input type? -
i want create form submit, i've created form using looping, need change last loop input type number select option
there's way how code?
form:
<div class="form-group"> <?php $stmt2 = $pgn2->readall(); while ($row2 = $stmt2->fetch(pdo::fetch_assoc)){ extract($row2); ?> <label for="ik"><?php echo $nama_kriteria; ?></label> <input type="hidden" name="ik[]" id="ik" value=<?php echo $id_kriteria ?>> <input type="number" class="form-control" id="nn" name="nn[]" min="1" max="100" <!-- want change last loop id="nn" --> placeholder="1 - 100"> <?php } ?> </div>
here's result form:
any idea appreciate
you can check if it's last row counting. :)
<div class="form-group"> <?php $stmt2 = $pgn2->readall(); $count = 1; $last = count($stmt2); while ($row2 = $stmt2->fetch(pdo::fetch_assoc)){ extract($row2); ?> <label for="ik"><?php echo $nama_kriteria; ?></label> <input type="hidden" name="ik[]" id="ik" value=<?php echo $id_kriteria ?>> <?php if($last === $count): ?> // add select input <-- <?php else: ?> <input type="number" class="form-control" id="nn" name="nn[]" min="1" max="100" placeholder="1 - 100"> <?php endif; $count++; } ?> </div>
Comments
Post a Comment