ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

5-6-5 ®Ö¨ú«ö¶s¡]Checkbox¡^

5-6-5 ®Ö¨ú«ö¶s¡]Checkbox¡^

5-6-5   ®Ö¨ú«ö¶s¡]Checkbox¡^
®Ö¨ú«ö¶s¡]Checkbox¡^¾A¥Î©ó¦h³Æ¿ï®×µª®×¥B¦h¥¿½Tµª®×¿ï¨úªº³õ¦X¡A¦p¦P½Æ¿ïªº¿ï¾ÜÃD¡A¨Ò¦p¿³½ì¡B¶Ý¦n¡Kµ¥¡G
  1. <input type=¡¨Checkbox¡¨ name=¡¨ÃѧO¦W¡¨ value=¡¨¸ê®Æ­È¡¨>
½Æ»s¥N½X
»P³æ¿ï«ö¶s¬Û¦Pªº¬O¨Ï¥ÎªÌ¥u»ÝÂI¿ïµª®×¡A¤£»Ý­n¶ñ¼g¸ê®Æ¡A©Ò¥H¥²¶·¬°¨C¤@­Ó®Ö¨ú«ö¶s«Ø¥ß¤£¦Pªº¸ê®Æ­È¡A¦Ó¥B¬°¤FÅý¦h­Ó®Ö¨ú«ö¶s¦¨¬°½Æ¿ïªº¸s²Õ¡A¬G¦P¸s²Õ¤ºªº®Ö¨ú«ö¶s¨ä¡uname¡vÄÝ©Ê­È¥²¶·¬°¬Û¦Pªº¡uÃѧO¦W¡v¡C
checkbox.php
  1. <html><head>
  2. <title>®Ö¨ú«ö¶s¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <form action="checkbox_ans.php" method="Post">
  5. ½Ð¿ï¾Ü±z³ßÅwªº¤ôªG:<Br>
  6. <Input type="Checkbox" name="food" value="­»¿¼" Checked>­»¿¼
  7. <Input type="Checkbox" name="food" value="Ä«ªG">Ä«ªG
  8. <Input type="Checkbox" name="food" value="ªÝ¼Ö">ªÝ¼Ö
  9. <Input type="Checkbox" name="food" value="»ñ±ù">»ñ±ù
  10. <Input type="Checkbox" name="food" value="¦è¥Ê">¦è¥Ê
  11. <Br>
  12. <input type="Submit">
  13. </form>
½Æ»s¥N½X
­Y­n±N¬Y­Ó®Ö¨ú«ö¶s¹w³]¬°¤w¿ï¨ú¡A«h¥[¤J¡uChecked¡vÄݩʳ]©w§Y¥i¡C»P³æ¿ï«ö¶s³Ì¤jªº¤£¦P¬O®Ö¨ú«ö¶s¦b¿ï¨ú«á¡A¥i¥H¦AÂI¿ï¤@¦¸®Ö¨ú«ö¶s¨ú®ø¿ï¨ú¡C

¹Ï5-27  ®Ö¨ú«ö¶s½d¨Òcheckbox.php¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

·í¦P®ÉÂI¿ï¦h­Ó®Ö¨ú«ö¶s«á¡A¦]¬°¨C­Ó®Ö¨ú«ö¶sªº¦WºÙ³£¬Û¦P¡A¦]¦¹¡A·í¸ê®Æ¶Ç°e«á¡A¨C­Ó³QÂI¿ïªº®Ö¨ú«ö¶s¨ä¸ê®Æ­È¤§¶¡·|¥H¤@­Ó¡u¡A¡v³r¸¹»P¤@­ÓªÅ¥Õ¦r¤¸¹j¶}¡A§Ú­Ì¥i¥H§Q¥Î¡ustr_replace()¡v¨ç¼Æ¥[¥H´À´«¡C

¹Ï5-28  ®Ö¨ú«ö¶s½d¨Òcheckbox_ans.php¡C
checkbox_ans.php
  1. <html><head>
  2. <title>®Ö¨ú«ö¶s¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <?
  5. $myfood=$_REQUEST["food"];
  6. ?>
  7. ±zªº¿ï¾Ü(´À¥N«e):<?=$myfood?>
  8. <P>
  9. ±zªº¿ï¾Ü(´À¥N«á):<?=str_replace(",",";",$myfood)?>
  10. </body></html>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

§AÄF¤H¡I§Ú¤£ºÞ¿ï¨ú´X­Ó¶µ¥Ø¡A¥¦´N¬O¥u·|¥X²{³Ì«á¤@­Ó³Q¿ï¨úªº¶µ¥Ø¡A¨þ¡A±zªº±¡§Î¬O¤£¬O¹³¹Ï5-28¤@¼Ë£«¡I³o¬OPHP¤¤ªº¤@­Ó³´¨À¡A¹³®Ö¨ú¤è¶ô³oºØ¤¸¥ó¡A¥i¥H¤@­ÓÃѧO¦WºÙ°O¿ý«Ü¦h¸ê®Æ¤º®eªºª¬ªp¡A§Ú­Ì¥Î¤@­ÓÃѧO¦W¨Ó³B²z·íµM¦æ¤£³q¡I¦]¦¹¡Aªí³æªº®Ö¨ú¤è¶ôÃѧO¦WÀ³¸Ó­n§â¥¦§ï¦¨°}¦C§Î¦¡¡G
checkbox_2.php
  1. <html><head>
  2. <title>®Ö¨ú«ö¶s¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <form action="checkbox_2_ans.php" method="Post">
  5. ½Ð¿ï¾Ü±z³ßÅwªº¤ôªG:<Br>
  6. <Input type="Checkbox" name="food[]" value="­»¿¼" Checked>­»¿¼
  7. <Input type="Checkbox" name="food[]" value="Ä«ªG">Ä«ªG
  8. <Input type="Checkbox" name="food[]" value="ªÝ¼Ö">ªÝ¼Ö
  9. <Input type="Checkbox" name="food[]" value="»ñ±ù">»ñ±ù
  10. <Input type="Checkbox" name="food[]" value="¦è¥Ê">¦è¥Ê
  11. <Br>
  12. <input type="Submit">
  13. </form>
  14. </body></html>
½Æ»s¥N½X
¬JµM®Ö¨ú¶µ¥Ø¤w¸g¦¨¬°°}¦CÅܼƪº¤¸¯À¡A¨º¸Ó¦p¦ó±N¤¸¯À¦C¥X©O¡H·Q°_¨Ó¤F§a¡I´N¬O§Ú­Ì¤w¸g¤¶²Ð¹Lªºfor°j°é£«¡G
checkbox_2_ans.php
  1. <html><head>
  2. <title>®Ö¨ú«ö¶s¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. ±zªº¿ï¾Ü:
  5. <?
  6. $myfood=$_REQUEST["food"];
  7. $num=count($myfood);
  8. for ($x=0; $x<$num; $x++)
  9. {
  10. echo "$myfood[$x] ,";
  11. }
  12. ?>
  13. </body></html>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¨Ï¥Îfor±Ô­z¿é¥X°}¦C¤¸¯À¬O°ò¥»¥\¡AÃø´NÃø¦b¦p¦ó¦b¿é¥X®É¬°¨C­Ó°}¦C¤¸¯À¶¡¥[¤J¤À¹j²Å¸¹¡A¹³¹Ï5-29¡A¬O¦b¨C­Ó°}¦C¤¸¯À¶¡¥[¤J³r¸¹¤F¡A¥i¬O¡A³Ì«á¤@­Ó¤¸¯À«á­±«o¦h¤F¤@­Ó³r¸¹¡A³o®É­Ô¡A§Ú­Ì¥i¥H§Q¥Î¡ujoin()¡v¨ç¼Æ¨Ó¸Ñ¨M¡G
checkbox_3_ans.php
  1. <html><head>
  2. <title>®Ö¨ú«ö¶s¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. ±zªº¿ï¾Ü:
  5. <?
  6. $myfood=$_REQUEST["food"];
  7. echo join(",",$myfood);
  8. ?>
  9. </body></html>
½Æ»s¥N½X
join()¨ç¼Æ¤£¶È¥i¦b¤¸¯À¶¡¥[¤J¯S©wªº¦r¦ê¡A¦P®É¤]±N°}¦C¤¤ªº¤¸¯À¤@¤@°µ¿é¥X¡A°£¤Fjoin()¨ç¼Æ¥~¡A¡uimplode()¡v¨ç¼Æ¥ç¦³¬Û¦P¥\¯à¡G
implode()¨ç¼Æ®æ¦¡
  1. string implode ( string glue, array pieces)
½Æ»s¥N½X
¨Ò¦p:½d¨Òex5_15.php
  1. <?
  2. $Myarray = array("¬K¤Ñ","®L¤Ñ","¬î¤Ñ","¥V¤Ñ");
  3. echo implode("<br>",$Myarray);
  4. //¿é¥X'¬K¤Ñ<br>®L¤Ñ<br>¬î¤Ñ<br>¥V¤Ñ'
  5. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¾Çªø,§Ú³o­ÓFUNCTION¥i¥H¼g±o¦A¦nÂI¶Ü
ÁÂÁÂ
  1. function showgroup(){
  2. $sql = 'SELECT * FROM `group` LIMIT 20';
  3. $result = mysql_query($sql);
  4. while ($row = mysql_fetch_assoc($result))
  5.             {
  6.                        
  7. echo $row['groupname']."'<input type='checkbox' name='perm[]' value='".$row['groupid']."'/>";
  8. }
  9. }
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¤@­Ó¯Ê¤fªºªM¤l¡A¦pªG´«¤@­Ó¨¤«×¬Ý¥¦¡A¥¦¤´µM¬O¶êªº¡C
ªð¦^¦Cªí ¤W¤@¥DÃD