php - How to show the value of the database to combobox? -


how show value of database combobox? i've tried this:

http://pastebin.com/gzl4qaps

$result = $koneksi->query(     "select tb_sekolah.idsekolah,         tb_sekolah.namasekolah,         tb_sekolah.tb_kategori_sekolah_idkategori,         tb_kategori_sekolah.namakategori,         tb_uptd.namauptd,         tb_sekolah.alamat,         tb_sekolah.telp,         tb_sekolah.katasandi,         tb_sekolah.status     tb_sekolah, tb_kategori_sekolah, tb_uptd     tb_sekolah.tb_kategori_sekolah_idkategori = tb_kategori_sekolah.idkategori     , tb_uptd.iduptd = tb_sekolah.tb_uptd_iduptd     , idsekolah='$id'" );  while ($row = $result->fetch_array()){      <select name="id_kategori" size="1" class="form-control" required>         <option label="-- pilih kategori --" ></option>         <?php //looping kategori         $result1 = $koneksi->query("select * tb_kategori_sekolah");              while ($row1 = $result1->fetch_array()){                                if ($row['tb_kategori_sekolah_idkategori']==$row1['idkategori']){                      $status = 'selected' ;                 } ?>                 <option <?php echo isset($status)?$status:''; ?> value="<?php echo $row1['idkategori'] ?>"><?php echo $row1['namakategori']; ?>                 </option>             <?php             }             ?>     </select> <?php } ?> 

were selected last value of tb_kategori_sekolah

it because have not set declare

$status = null;

inside while function

your code suppose this

<select name="id_kategori" size="1" class="form-control" required>     <option label="-- pilih kategori --" ></option>     <?php //looping kategori     $result1 = $koneksi->query("select * tb_kategori_sekolah");          while ($row1 = $result1->fetch_array()){                            // declare null             $status = null;               if ($row['tb_kategori_sekolah_idkategori']==$row1['idkategori']){                  $status = 'selected' ;             } ?>             <option <?php echo isset($status)?$status:''; ?> value="<?php echo $row1['idkategori'] ?>"><?php echo $row1['namakategori']; ?>             </option>         <?php         }         ?> </select> 


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -