..yan po database ko, sa course table, may bawat subjects, at gusto ko ipalabas sa dropdown ng
sa dropdown naman, kapag pipili ako ng course, lalabas sa subject na dropdown ang lahat ng subject under ng napiling course na ang dropdown course ay may value ng bawat course example:
<select name="course">
<option value="act">ACT</option>
<option value="beed">BEED</option>
<option value="bsba">BSBA</option>
<option value="bsed">BSED</option>
<option value="bshrm">BSHRM</option>
<option value="bsit">BSIT</option>
<option value="bstm">BSTM</option>
</select>
at lalabas ang subject na nasa course table kapag pipili ng course sa select option na course,
<select name="subject">
<option value="math 0">Match 0</option>
<option value="english 1">English 1</option>
</select>
Separate kasi ang bawat course ng bawat subject.
respect po at sana may tumulong.
Ito po yong source code ko:
<=============================================>
Add New Schedule<=============================>
<?php require_once('functions/function.php' );
$con = mysqli_connect("localhost","root","");
if($con->connect_error){
die("Error Connecting to server".$con->connect_error);
}
if(!mysqli_select_db($con,"student_info")){
echo "Database not selected";
}
$tbl_instructor="SELECT instructor_name FROM instructor";
$result = $con->query($tbl_instructor);
// $subject = "SELECT student_subject from'".$_."'";
// $rs = $con->query($subject);
?>
<?php get_header();?>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-9 col-lg-9 w3-cards-4">
<h3 class="page-header">Add New Schedule</h3>
<form method="post" action="includes/new-schedule.php" class="w3-container w3-cards-4">
<label class="w3-label">Edp Code</label>
<input placeholder="Edp Code" type="number" name="edp_code" class="w3-input w3-border" />
<label class="w3-label">Select Course</label>
<select name="course" class="w3-input w3-border" onchange="showUser(this.value)">
<option value="act">ACT</option>
<option value="beed">BEED</option>
<option value="bsba">BSBA</option>
<option value="bsed">BSED</option>
<option value="bshrm">BSHRM</option>
<option value="bsit">BSIT</option>
<option value="bstm">BSTM</option>
</select>
<label class="w3-label">Subject</label>
<select name='subject_name' class='w3-input w3-border' id="txtHint"></select>
<label class="w3-label">Day</label>
<input placeholder="Day" type="number" name="schedule_day" class="w3-input w3-border" />
<label class="w3-label">Time</label>
<input placeholder="Time" type="time" name="schedule_day" class="w3-input w3-border" />
<label class="w3-label">Instructor</label>
<select name='instructor' class="w3-input w3-border">
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<option value=".$row["instructor_name"].">".$row["instructor_name"]."</option>";
}
} else {
echo "0 results";
}
$con->close();
?>
</select>
<br/>
<input type="submit" value="Insert Schedule" name="submit" class="w3-btn w3-orange" />
</form>
</div>
<div class="col-sm-12 col-md-3 col-lg-3">
<?php require_once('sidebar.php');?>
</div>
</div>
</div>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").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 (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","get_subject.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<?php get_footer();?>
<============================================================>
para sa dropdown subject
<?php
$con = mysqli_connect("localhost","root","");
if($con->connect_error){
die("Error Connecting to server".$con->connect_error);
}
if(!mysqli_select_db($con,"student_info")){
echo "Database not selected";
}
$q = intval($_GET['q']);
// $s = intval($_POST['student_subject']);
$sql="SELECT subject_name FROM course WHERE course_name = '".$q."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo "<option value='".$row['subject_name']."'>" . $row['subject_name'] . "</option>";
}
mysqli_close($con);
?>
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
Last edited: