我已经为PHP考试大厅安排了座位设置。大厅名称由用户手动提供,它应该在表格列中查看,其中作为来自mysql数据库的寄存器号,值应按行在逻辑上查看,两者必须同时完成。如何实现
霍尔名称 - > Coloumn wise ::注册名称 - > 行明智
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Move from one select box to another</title>
<style type="text/css">
select {
width: 200px;
float: left;
}
.controls {
width: 40px;
float: left;
margin: 10px;
}
.controls a {
background-color: #222222;
border-radius: 4px;
border: 2px solid #000;
color: #ffffff;
padding: 2px;
font-size: 14px;
text-decoration: none;
display: inline-block;
text-align: center;
margin: 5px;
width: 20px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
function displayCount() {
var count = $('#from option').length;
document.getElementById("countFrom").value=count;
var count2 = $('#to option').length;
document.getElementById("countTo").value=count2;
}
function moveAll(from, to) {
$('#'+from+' option').remove().appendTo('#'+to);
var count = $('#from option').length;
document.getElementById("countFrom").value=count;
var count2 = $('#to option').length;
document.getElementById("countTo").value=count2;
}
function moveSelected(from, to) {
$('#'+from+' option:selected').remove().appendTo('#'+to);
var count = $('#from option').length;
document.getElementById("countFrom").value=count;
var count2 = $('#to option').length;
document.getElementById("countTo").value=count2;
}
function selectAll() {
$("select option").attr("selected","selected");
var count = $('#from option').length;
document.getElementById("countFrom").value=count;
var count2 = $('#to option').length;
document.getElementById("countTo").value=count2;
}
function getValues() {
var hallName="";
var tex = $( "#to option:selected" ).text();
var count3 = $('#to option').length;
var x=document.getElementById("to");
for (var i = 0; i < x.options.length; i++) {
if(x.options[i].selected ==true){
// alert(x.options[i].value);
hallName += x.options[i].value+"-";
}
}
document.getElementById("hallName").value=hallName;
alert(hallName);
}
</script>
</head>
<body>
<form name="selection" method="post" onSubmit="return selectAll()">
<input type="text" name="hallName" id="hallName" onclick="show();">
<input type="submit" name="my_form_submit_button" value="Second Click"/>
<body onload="displayCount();">
<select multiple size="10" id="from">
<option value="hall 1">hall 1</option>
<option value="hall 2">hall 2</option>
<option value="hall 3">hall 3</option>
<option value="hall 4">hall 4</option>
<option value="hall 5">hall 5</option>
<option value="hall 6">hall 6</option>
<option value="hall 7">hall 7</option>
<option value="hall 8">hall 8</option>
<option value="hall 9">hall 9</option>
<option value="hall 10">hall 10</option>
</select>
<div class="controls">
<a href="javascript:moveAll('from', 'to');" onclick="return ccfromto();" id="get">>></a>
<a href="javascript:moveSelected('from', 'to');" onclick="return ccfromto();" id="get">></a>
<a href="javascript:moveSelected('to', 'from');" onclick="return ccfromto();" id="get"><</a>
<a href="javascript:moveAll('to', 'from');" onclick="return ccfromto();" id="get"><<</a>
</div>
<select multiple id="to" size="10" name="topics[]"></select>
<br></br>
<br></br>
<br></br>
<br></br>
<br></br>
<br></br>
<input type="text" name="countFrom" id="countFrom">
<input type="text" name="countTo" id="countTo">
<br>
<input type="button" name="but" value="after moving first click" id="but" onclick="return getValues();">
</br>
</form>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cms";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql='select register_number from stu_master ';
$result = $conn->query($sql);
$count = 0;
echo "<table>";
echo "<tr>";
$name=$_POST["hallName"];
$arr1=explode("-",$name);
$arr_length = count($arr1);
$countRow=0;
for ($i = 0; $i < $arr_length-1; $i++) {
for ($j = 1; $j <= 5; $j++) {
if($countRow == 1) {
echo "</tr><br><tr>";
$countRow = 0;
}
echo "<td>".$arr1[$i]." "."Row"." ".$j."</td><br>";
while ($show = mysqli_fetch_array($result)) {
if($count == 5) {
echo "</tr><br><tr>";
$count = 0;
}
echo "<td>".$show[register_number]."</td>";
$count++;
}
$countRow++;
}
}
echo "</tr>";
?>
</table>
</body>
</html>
答案 0 :(得分:0)
不知怎的,我管理并带来了所需的输出。我将单独发布php部分,以便对某人有用
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cms";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql='select register_number from stu_master';
$result = $conn->query($sql);
$count = 0;
echo "<table>";
echo "<tr>";
$name=$_POST["hallName"];
$arr1=explode("-",$name);
$arr_length = count($arr1);
$countRow=0;
$show=array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$show[]= $row[register_number];
}
$size=count($show);
echo $size;
$var=0;
for ($i = 0; $i < $arr_length-1; $i++)
{
for ($j = 1; $j <= 5; $j++)
{
if($countRow == 1)
{
echo "</tr><br><tr>";
$countRow = 0;
}
echo "<td>".$arr1[$i]." "."Row"." ".$j."</td><br>";
echo "<td>".$show[$var+0]."</td>";
echo "<td>".$show[$var+1]."</td>";
echo "<td>".$show[$var+2]."</td>";
echo "<td>".$show[$var+3]."</td>";
echo "<td>".$show[$var+4]."</td>";
$countRow++;
$var=$var+5;
}
}
echo "</tr>";
?>