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

AI Hentai Generator
Generate AI Hentai for free.

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

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
