### CyBoard ###
 
 
3.144.224.32
 
¡Ä¡Ä Á¤±¤Ãµ ¡Ä¡Ä
°Ô½ÃÆÇ
 
  01. ±â¼ú¹®¼­  
±Û¾´ÀÌ Á¤±¤Ãµ Á¶È¸¼ö 12408
À̸ÞÀÏ ÀÛ¼ºÀÏ 2006-02-26 22:02:25
Á¦¸ñ [PHP] 2´Ü°è select ¹Ú½º
$sql = "
   select distinct bub_cd, bub_name, gae_code, gae_name
     from mj_bub_cd
    where bub_cd is not null
      and bub_cd is not null
      and gae_code is not null
      and gae_name is not null
 order by bub_cd, gae_code
";
$result1 = mysql_query($sql);
echo "
      <Script Language='javaScript'>
      <!--
         //==========================================================//
         // Element ¹× °ª Á¤ÀÇ
         //==========================================================//
         thisFormName             = 'fm_select';   // Æû ³×ÀÓ.
         FirstSelectName          = 'i_select1';      // óÀ½ Select ElementÀÇ À̸§
         SecondSelectName         = 'i_select2';      // µÎ¹ø° Select ElementÀÇ À̸§
         FirstSelectText          = new Array();
         FirstSelectValue         = new Array();
         SecondSelectText         = new Array();
         SecondSelectValue        = new Array();
         SecondSelectText[0]      = new Array();
         SecondSelectValue[0]     = new Array();
         FirstSelectText[0]       = '-- ¼± ÅÃ --';
         FirstSelectValue[0]      = '0';
         SecondSelectText[0][0]   = '-- ¼± ÅÃ --';
         SecondSelectValue[0][0]  = '0';
";
while ($iv_row1 = mysql_fetch_array($result1))
{
   if ($ls_bub_cd != $iv_row1[bub_cd])
   {
      $i++;
      $j=0;
      $ls_bub_cd = $iv_row1[bub_cd];
      echo "
         FirstSelectText[$i]  = '$iv_row1[bub_name]';
         FirstSelectValue[$i] = '$iv_row1[bub_cd]';
         SecondSelectText[$i]  = new Array();
         SecondSelectValue[$i] = new Array();
      ";
   }
   echo "
         SecondSelectText[$i][$j]  = '$iv_row1[gae_name]';
         SecondSelectValue[$i][$j] = '$iv_row1[gae_code]';
   ";
   $j++;
}
echo "
         function CreateSecondSelect()
         {
             var f = document.forms[thisFormName];
             var n = f[FirstSelectName].selectedIndex;
             var l = SecondSelectText[n].length;
             f[SecondSelectName].options.length = l;
             for(var i=0;i<l;i++)
             {
                 f[SecondSelectName].options[i].text = SecondSelectText[n][i];
                 f[SecondSelectName].options[i].value = SecondSelectValue[n][i];
             }
             f[SecondSelectName].selectedIndex=0;
         }
         document.write(\"<select name='\"+FirstSelectName+\"' onChange='CreateSecondSelect()'>\");
         for(var i=0;i < FirstSelectText.length;i++)
         document.write(\"<option value='\"+FirstSelectValue[i]+\"'>\"+FirstSelectText[i]+\"</option>\");
         document.write(\"</select>\");
         document.write(\"<select name='\"+SecondSelectName+\"'>\");
         document.write(\"<option value=''></option>\");
         document.write(\"</select>\");
         CreateSecondSelect();
         document.forms[thisFormName].i_select1.value='".($i_select1 ? $i_select1 : 0)."';
         CreateSecondSelect();
         document.forms[thisFormName].i_select2.value='".($i_select2 ? $i_select2 : 0)."';
      //-->
      </script>
";

IP Address : 220.84.225.17