PHP+mysql实现二级级联下拉框的问题
请教大虾门,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>
回复讨论(解决方案)
自己解决了,最后发现时读取二维数组的问题。。。。。。
哦,我之前也遇到过类似问题,解决了就好,哈哈。。。
我也遇到这样的问题啊,解决不了!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

In PHP, the difference between include, require, include_once, require_once is: 1) include generates a warning and continues to execute, 2) require generates a fatal error and stops execution, 3) include_once and require_once prevent repeated inclusions. The choice of these functions depends on the importance of the file and whether it is necessary to prevent duplicate inclusion. Rational use can improve the readability and maintainability of the code.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.
