问题一:
在这个页面掉选出来的名单中,我想通过勾选几个名单,加载到下一个页面中,请问这里如何实现?目前出现的情况是:不管我勾选几个,总是会自动选择2人。
问题二:
假设有一个页面A,而这个代码是页面B的,提交以后到页面C,而页面B显示在页面A的
<?php require_once('Connections/games.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
$isValid = False;
if (!empty($UserName)) {
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "d_dl_false.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?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_athletes = "SELECT * FROM athletes";
$athletes = mysql_query($query_athletes, $games) or die(mysql_error());
$row_athletes = mysql_fetch_assoc($athletes);
$totalRows_athletes = mysql_num_rows($athletes);
$colname_delegations = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_delegations = $_SESSION['MM_Username'];
}
mysql_select_db($database_games, $games);
$query_delegations = sprintf("SELECT * FROM delegations WHERE dname = %s", GetSQLValueString($colname_delegations, "text"));
$delegations = mysql_query($query_delegations, $games) or die(mysql_error());
$row_delegations = mysql_fetch_assoc($delegations);
$totalRows_delegations = mysql_num_rows($delegations);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>【报名 】</title>
<link href="css/bootstrap-4.4.1.css" rel="stylesheet" type="text/css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('#submitButton').click(function(event) {
event.preventDefault(); // 阻止表单的默认提交行为
// 创建一个空数组来存储被选中的运动员的ID
var selectedAthletes = [];
// 遍历所有的复选框
$('input[type="checkbox"]').each(function() {
// 如果复选框被选中,则将其值(运动员ID)添加到数组中
if ($(this).is(':checked')) {
selectedAthletes.push($(this).val());
}
});
// 如果至少有一个运动员被选中,则发送AJAX请求
if (selectedAthletes.length > 0) {
$.ajax({
url: 'd_center.php', // 替换为实际的服务器端点URL
type: 'POST',
data: { athletes: selectedAthletes }, // 发送被选中的运动员ID数组
success: function(response) {
// 如果请求成功,处理服务器的响应
// 假设服务器返回的是HTML内容,将其显示在<main>标签中
$('main').html(response);
},
error: function(jqXHR, textStatus, errorThrown) {
// 如果请求失败,显示错误消息
console.error('AJAX请求失败: ' + textStatus, errorThrown);
alert('提交失败,请检查网络或联系管理员。');
}
});
} else {
// 如果没有选中任何运动员,显示一个提示消息
alert('请至少选择一个运动员。');
}
});
});
</script>
</head>
<body>
<div class="container-md">
<table class="table">
<tr>【 队伍报名表信息确认 】</tr>
<tr align="center">
<td>序号</td>
<td>选择</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
<td>教练</td>
<td>出生日期</td>
<td>信息修改</td>
</tr>
<?php
//从'delegations'记录集中调取'dname'
$dname = $row_delegations['dname'];
if($dname!=' '){
$maxRowCount = mysql_num_rows($athletes);
// 根据'dname',从athletes记录集中调取出对应信息
$athletes = "select * from athletes where dname = '$dname' group by aname order by birthday desc" ;
$athletes =mysql_query($athletes) or die("查询失败");
}
$serial_number = 1;
?>
<?php while ($row = mysql_fetch_assoc($athletes)): ?>
<tr align="center">
<td><?php echo $serial_number; ?></td>
<td>
<?php echo "<input type='checkbox' name='athletes[]' value='" . $row['arealname'] . "'>"; ?>
</td>
<td><?php echo $row['arealname']; ?></td>
<td><?php echo $row['gender']; ?></td>
<td><?php echo $row['age']; ?></td>
<td><?php echo $row['coach']; ?></td>
<td><?php echo $row['birthday']; ?></td>
<td>修改</td>
</tr>
<?php $serial_number++; ?>
<?php endwhile; ?>
</table>
<form action="reg_match_list.php" method="post" id="reg_match_Form">
<input type="submit" value="添加名单">
</form>
</div>
<main class="container" id="content"></main>
</body>
</html>
<?php
mysql_free_result($athletes);
mysql_free_result($delegations);
?>