본문 바로가기
PHP

for 문으로 select 항목들 불러오기

by sj0020 2021. 7. 5.

<div class="form-group">
                      <label for="inputName">은행</label>
                      <input type="hidden" name="" value="collect_bank">
                      <select class="form-control" id = "collect_bank"  name="param">
                        <option value="">은행선택</option>
                        <!-- 은행 리스트 불러오기 -->
                        <?php
                          $bank_sql = "SELECT * FROM [bank_data] WHERE bank_type ='시중은행' OR bank_type = '지방은행'";
                          $bank_result = sqlsrv_query($con,$bank_sql,$params,$options);
                          $bank_total = sqlsrv_num_rows($bank_result);

                          for ($i=0; $i <$bank_total ; $i++) {
                            $bank_row = sqlsrv_fetch_array($bank_result);
                            $bank = $bank_row['bank_name'];
                            ?>
                            <option value="<?=$bank?>"><?=$bank?></option>
                          <?php } ?>
                        ?>
                      </select>
                    </div>