请教大虾门,PHP+mysql实现二级级联下拉框,解决班级很多的情况下,先选择入学年份再选择属于这一年的班级的问题。
第一个下拉框中的年份可以读出来,但是当选择某一年之后,班级下拉框中什么都没有显示,代码如下,请大虾们看看问题出在哪儿,谢谢了先
/***********************************************
**
** 数据库:数据库名(alumni)、数据表(enteryear、banji)
** 表enteryear中字段:enter_id(id编号)、entertime(年份)
** 表banji中的字段:id(id编号)、classnum(班级号)、enteryear(年份)
***********************************************/
//****************** 连接选择数据库 ***************
$link = mysql_connect("localhost", "root", "")
or die("Could not connect : " . mysql_error());
mysql_select_db("alumni") or die("Could not select database");
//******************提取省份信息******************
$sqlSel = "select * from enteryear order by enter_id ";
$result = mysql_query($sqlSel) or die("Query failed : " . mysql_error());
$forum_data = array();
while( $row = mysql_fetch_array($result) )
{
$forum_data[] = $row;
}
//print_r ($forum_data);
mysql_free_result($result);
//**************获取城市信息**************
$sqlSel2 = "select * from banji order by id desc";
if( !($result2 = mysql_query($sqlSel2)) )
{
die('Could not query t_city list');
}
$forum_data2 = array();
while( $row2 = mysql_fetch_array($result2) )
{
$forum_data2[] = $row2;
}
mysql_free_result($result2);
?>
<script> <br /> var onecount2; <br /> subcat2 = new Array(); <br /> <?php <br /> $num2 = count($forum_data2); <br /> ?> <br /> onecount2=<? echo $num2;?>; <br /> <? <br /> for($j=0;$j<$num2;$j++) <br /> { <br /> ?> <br /> subcat2[<? echo $j;?>] = new Array("<? echo $forum_data2[$j]['id'];?>","<? echo $forum_data2[$j]['classnum'];?>","<? echo $forum_data2[$j]['entertime'];?>"); <br /> <? <br /> } <br /> ?> <br /> function changelocation(id) <br /> { <br /> document.myform.classnum.length = 0; <br /> var id=id; <br /> var j; <br /> document.myform.classnum.options[0] = new Option('==选择班级==',''); <br /> for (j=0;j < onecount2; j++) <br /> { <br /> if (subcat2[j][1] == id) <br /> { <br /> document.myform.classnum.options[document.myform.classnum.length] = new Option(subcat2[j][2], subcat2[j][0]); <br /> } <br /> } <br /> } <br /> </script>
回复讨论(解决方案)
自己解决了,最后发现时读取二维数组的问题。。。。。。
哦,我之前也遇到过类似问题,解决了就好,哈哈。。。
我也遇到这样的问题啊,解决不了!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
