我想这会链接回我的previous question.
我有一个选择框,根据他们是否确认他们将参加活动,打印出一个名单列表。
<html>
<head>
<script>
$('#users option').click(function() {
$(this).clone().appendTo("#users2");
});
</script>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("attendYes").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("attendYes").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","attending.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value);">
<option value="">Select a group:</option>
<option value="CMA">CMA</option>
<option value="CM1">CM1</option>
<option value="CP2">CP2</option>
<option value="CBBC">CBBC</option>
</select>
</form>
<form>
<select name="users2" value="">
<option value="">--</option>
</select>
</form>
<form>
<select name="users3" value="">
<option value="">--</option>
</select>
</form>
<br>
<div id="attendYes"><b>Person info will be listed here...</b></div>
<div id="attendNo"><b>Person info will be listed here...</b></div>
<div id="attendUn"><b>Person info will be listed here...</b></div>
</body>
</html>
现在通过attending.php检索播放器列表 - 虽然我已经创建了notattending.php和unconfirm.php以及每个中的相关SQL更改(我觉得它更容易?)。
<?php
$q = $_GET['q'];
$con = mysqli_connect('------','------','------','------');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"handsomejack_co_forms");
$sql="SELECT * FROM stats WHERE activity='".$q."' AND attend='1' ORDER BY username ASC";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>User</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
我想要发生的是针对用户&#39;中选择的群组。被设置为&#39; users2&#39;的组。和&#39; users3&#39;,允许他们在&#39; attendNo&#39;中打印他们自己的列表。并且&#39;参加Un&#39;。
正如您在第一个代码块中看到的那样,我试图克隆数据无济于事,我不知道接下来会尝试什么。
有没有人有任何建议或帮助我指明正确的方向?
编辑 - 我现在将列表打印到所有三个区域(是,否,未确认),但它仍然只打印一个sql结果。更新了下面的脚本和SQL
<script>
function showUser(str) {
if (str == "") {
document.getElementById("attendYes").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("attendYes").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","attending.php?q="+str,true);
xmlhttp.send();
}
if (str == "") {
document.getElementById("attendNo").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("attendNo").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","attending.php?w="+str,true);
xmlhttp.send();
}
if (str == "") {
document.getElementById("attendUn").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("attendUn").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","attending.php?e="+str,true);
xmlhttp.send();
}
}
</script>
<?php
$q = $_GET['q'];
$w = $_GET['w'];
$e = $_GET['e'];
$con = mysqli_connect('------','------','------','------');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"handsomejack_co_forms");
$sql="SELECT * FROM stats WHERE activity='".$q."' AND attend='1' ORDER BY username ASC";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>User</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "</tr>";
}
$sql="SELECT * FROM stats WHERE activity='".$w."' AND attend='2' ORDER BY username ASC";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>User</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "</tr>";
}
$sql="SELECT * FROM stats WHERE activity='".$e."' AND attend='0' ORDER BY username ASC";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>User</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>