다음을 고려하십시오.이 작업을 수행하려고합니다. 1) 학기를 선택하는 데 사용할 수있는 드롭 다운 목록이 있습니다. 2) 일단 학기를 선택하면 해당 학기의 강좌가 다른 강좌 목록에 나타나야합니다. 3) 학기 변경에 따라 과정을 변경해야 할 수도 있습니다.데이터베이스에서 드롭 다운 목록에 대한 채우기 옵션
내 데이터베이스
이 내가 아약스, PHP와 MySQL을 사용했던 것입니다course_info(courseID varchar(15) primary key,courseName varchar(30),semester int)
.
내 HTML 페이지
<html>
<head>
<script>
function showsemester(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","showsemester.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showsemester(this.value)">
<option value="">Select a semester:</option>
<option value="1">Y i S i</option>
<option value="2">Y i S ii</option>
</select>
</form>
<br>
<div id="txtHint"><b>courses will be listed here.</b></div>
</body>
내 PHP 페이지
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','','scifac');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
$sql="SELECT * FROM course_info WHERE semester = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table border='1'><tr><th>course ID</th><th>name</th><th>semester</th></tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>". $row['courseID'] . "</td>";
echo "<td>" . $row['courseName'] . "</td>";
echo "<td>" . $row['semester'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
는 이제 테이블 제대로 작동으로 사업부에 결과를 생산 어떤 오류없이. 그러나 나는 드롭 다운리스트와 코스 ID의 옵션으로 코스 명을 값으로 삼고 싶습니다.
이와 관련하여 귀하의 친절한 배려가 높게 평가됩니다. 감사합니다. T
같이해야한다. 너 뭐 해봤 니? –
문제가있는 곳을 볼 수 없습니다. 데이터를 테이블로 가져올 수 있습니다 ... – TheOneWhoPrograms