¤u¼tª½Àç¡A´£¨Ñµ¡Ã®¡B¾À¯È¡B¾À¥¬ ¦a´àµ¥³]p¸ËæC¤Î¾ãÅé·f°t¡A»ù®æ¶WÀu´f | ³»¦y¸ËæC¶q¨³W¹ºªÅ¶¡ ¥H¤H©Ê¾÷¯à¬°Àu¥ý¦Ò¶q¡A³Ð³y¹ê¥Î¬ü¾Ç½è·P¥Í¬¡ |
[JQuery] cascade PHP+MYSQL°ÊºA¿ï³æÀ³¥Î |
©ÐªF¡G¤p©f µoªí®É¶¡¡G2011-03-23 | [ÀËÁ|] |
1.½Ð¥ý¤U¸üjqueryÀÉ®× <select name="class1[]" id="class1">
<select name="c_name[]" id="c_name"><option value="">Store Name</option></select>
<script>
<?php require_once(\'Connections/mio.php\');//¤Þ¤J¸ê®Æ®w³sµ²ÀÉ ?>
|
1 ¼Ó¦í¤á¡Gjack µoªí®É¶¡¡G2011-03-23 | [ÀËÁ|] |
Ãö©óAjax¡A§Ú·Q³Ì´Îªº¦a¤è´N¬O¥i¥H©óI´º©I¥s¸ê®Æ®w¶Çȧa¡ã¦h«¤U©Ô¦¡¿ï³æ´N¬O¤@¶µ«D±`´ÎªºAjaxÀ³¥Î¡F«e´X¤ÑJace¥á¹L¨Ó¤@Ó°ê¥~ªººô§}¡GjQuery.cascade : Cascading values from forms¡A³o½g¤å³¹¥Dn¬O¦b»¡©újQueryªºcascade¡A¦Ó¥¦´N¬O¥Î¨Ó¹ê²{¦h«¤U©Ô¦¡¿ï³æªº¥\¯à¡C ªá¤F¤@ÂI®É¶¡¹ê§@¤F¤@¤U¡Aµo²{«D±`²³æ´N¯à¹ê²{¡I¥H«e§Ú¤]§@¹LÃþ¦üªº¥\¯à¡A¥i¬Oªá¤F§Ú«D±`¦hªº®É¶¡...jQuery§â¥¦¥]¸Ë°_¨Ó¡AÅý¤@¤ÁÅܪºÂ²³æ¦h¤F¡F¥H¤U¬O²³æªº½d¨Ò¡Aµ¹¦³»Ýnªº¤H°Ñ¦Ò§a¡G½d¨Ò¬O¤T¶¥¼hªºÃöÁp¦¡¦h«¤U©Ô¦¡¿ï³æ¡A¤À¬°index.php¡]§e²{¶¡^¡Baction.php¡]Ajax«áºÝ¸ê®Æ³B²z¶¡^¡B¥H¤ÎjQueryªºcascade index.php¡G �Ĥ@�� �@ �ĤG�� �ĤT�� action.php�G // ��Ʈw�]�w $host_sql = "localhost"; $username_sql = "username"; $password_sql = "password"; $link = mysql_connect($host_sql, $username_sql, $password_sql) or die("�L�k�s����Ʈw"); mysql_select_db('target', $link); mysql_query("SET NAMES UTF8"); if (!empty($_GET['act'])) { $action = $_GET['act']; } if (!empty($_GET['val'])) { $parentId = $_GET['val']; } $list = '['; switch ($action) { case 'first': $query = "SELECT id, name FROM table where lv = 2 AND parentid= $parentId"; $result = mysql_query($query, $link); while ($row = mysql_fetch_assoc($result)) { $list .= '{\'When\':\'' . $parentId . '\',\'Value\':\'' . $row["id"] . '\',\'Text\':\'' . $row["name"] . '\'},'; } break; case 'second': default : $query = "SELECT id, name FROM table where lv = 3 AND parentid = $parentId"; $result = mysql_query($query, $link); while ($row = mysql_fetch_assoc($result)) { $list .= '{\'When\':\'' . $parentId . '\',\'Value\':\'' . $row["id"] . '\',\'Text\':\'' . $row["name"] . '\'},'; } break; } $list .= ']'; echo $list; ��@�����I�O�b��ƪ��榡�G list = [{'When':'A1','Value':'W','Text':'SubchildA1a'}, {'When':'A1','Value':'X','Text':'SubchildA1b'}, ]; �䤤When�N���W�@���h���ȡAValue�O���@���h���ȡATest�h�O�U�Ԧ������ܪ���r�F�n�S�O�`�NJavaScript�O�j�p�g�ӷP���I��@�o�ӽd�ҳ~���A���g�Q�j�p�g��F�@�q�ɶ�...��Ӥ~�o�{��ҥH�o�a��n�S�O�`�N�I�Ʊ�j�a���໴�P�g�X���p��Ʈw���h���U�Ԧ�����o^^http://blog.roodo.com/taikobo0/archives/6166625.html |