简体   繁体   中英

SELECT OPTION from mysql field value

I need to populate an html SELECT OPTION using a while loop with an sequence from 1 to the value of a integer number that is stored in a field called dummy3 inside a table from mysql database.

Example: if the dummy3 field has number 4, than the select option should display 1 2 3 4 as option values.

Here is my code, that is not working. The option values in this code version always come empty (with other code variants i tried the browser looped forever).

Here is my code:

echo 'Quantidade: '.'<select name="product_qty" id="product_qty" class="btn">';
     $qt = 1;
     $quantidade = "SELECT dummy3 FROM shop_products ORDER BY category ASC";
     $quantidade1 = mysqli_query($conn, $quantidade) or die("database error:". mysqli_error($conn));
       while($row_quantidade = mysqli_fetch_assoc($quantidade1, MYSQL_NUM)){
         $row_qt = $row_quantidade['dummy3'];
         while($qt <= $row_quantidade['dummy3']){
           echo '<option value="'.$qt.'">'.$qt.'</option>';
         }
      }
echo '</select>';
echo 'Quantidade: '.'<select name="product_qty" id="product_qty" class="btn">';
     $qt = 1;
     $quantidade = "SELECT dummy3 FROM shop_products ORDER BY category ASC";
     $quantidade1 = mysqli_query($conn, $quantidade) or die("database error:". mysqli_error($conn));
       while($row_quantidade = mysqli_fetch_assoc($quantidade1, MYSQL_NUM)){
         $row_qt = $row_quantidade['dummy3'];
         for($i = 1; $i <= $row_qt; $i++) {
           echo '<option value="'.$i.'">'.$i.'</option>';
         }
      }
echo '</select>';

Does this work?

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