情况说明:
数据库里有一个名为matchs的表,表中有有game、match、mname、mdate、maddress共5个关键字,
主要操作查询的网页名为:reg_match_list.php
我需要在reg_match_list.php页面中,插入3个下拉菜单分别为“game_select”、“match_select”、“mname_select”,需要三者实现联动;
第一个"game_select"下拉菜单的数值,是从数据库matchs表中game字段中获取,并且是唯一值;
当我选择第一个下拉菜单中某个数值后,第二个“match_select"下拉菜单就会匹配数据库中game字段的数据,来调取match字段的数据作为它的下拉菜单数据内容;
当我再选择第二个下单菜单中的数值后,第三个"mname_select"下拉菜单就会匹配数据库中match字段的数据和game字段的数据,来调取相应的mname字段的内容来作为下拉菜单的数据内容。
并且将对应的mname内容的mdate和maddress内容显示在页面上。
以下是我原来的代码,二级菜单无法获取数据,请问如何解决?
<?php require_once('Connections/games.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_games, $games);
$query_game = "SELECT DISTINCT game FROM matchs where state = 1 ORDER by game desc";
$game = mysql_query($query_game, $games) or die(mysql_error());
$row_game = mysql_fetch_assoc($game);
$totalRows_game = mysql_num_rows($game);
$colname_match = "-1";
if (isset($_SESSION['game'])) {
$colname_match = $_SESSION['game'];
}
mysql_select_db($database_games, $games);
$query_match = sprintf("SELECT * FROM matchs WHERE game = %s", GetSQLValueString($colname_match, "text"));
$match = mysql_query($query_match, $games) or die(mysql_error());
$row_match = mysql_fetch_assoc($match);
$totalRows_match = mysql_num_rows($match);
?>
<?php $_SESSION['game']; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Matches Selector</title>
<form method="post" name="game">
<select id="game-select">
<option value="请选择">请选择</option>
<?php
do {
?>
<option value="请选择"><?php echo $row_game['game']?></option>
<?php
} while ($row_game = mysql_fetch_assoc($game));
$rows = mysql_num_rows($game);
if($rows > 0) {
mysql_data_seek($game, 0);
$row_game = mysql_fetch_assoc($game);
}
?>
</select>
</form>
<select id="matches-select">
<?php
do {
?>
<option value="请选择"</option>
<?php
} while ($row_match = mysql_fetch_assoc($match));
$rows = mysql_num_rows($match);
if($rows > 0) {
mysql_data_seek($match, 0);
$row_match = mysql_fetch_assoc($match);
}
?>
</select>
<select id="mname-select"></select>
</form>
</body>
</html>
<?php
mysql_free_result($game);
mysql_free_result($match);
?>


