Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // query data from database
- $pilihan=mysql_query(
- "SELECT a.id_sub_kategori,b.id_kategori,b.nama_kategori,a.nama_subkategori
- FROM subkategori a INNER JOIN kategori b ON a.id_kategori=b.id_kategori
- WHERE b.aktif='Y'
- ORDER BY b.id_kategori,a.id_subkategori"
- );
- // store given data to an array
- $opts=array();
- while($r=mysql_fetch_array($pilihan)){
- $opts[]=$r;
- }
- $its_group=0;// its option new group?
- $group=''; // group label
- // build a list of options
- ?>
- <select name="subkategori>
- <option value="0" selected="selected">-- pilih kategori</option>
- <?php
- for($i=0;$i<count($opts);$i++){
- if($group==''|| $group!=$opts[$i]['nama_kategori']){
- $group=$opts[$i]['nama_kategori'];
- $its_group=1;
- echo "<optgroup label=\"".$opts[$i]['nama_kategori']."\">\n"
- }
- echo "<option value=\"".$opts[$i]['id_subkategori']."\">"
- .$opts[$i]['nama_subkategori']
- ."</option>\n";
- if($its_group){
- echo "</optgroup>\n";
- $its_group=0;
- }
- }
- ?>
- </select>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement