たとえば、私は摂取量とコースのデータベースを持っています。私はAとBのデータを持っています。 コースでは、私は外部キーとして摂取量AのPHPを、外部キーとして摂取量BのJqueryを持っています。だからフォームで、私が "A"を摂取量として選択した場合、後でコースのオプションまたはドロップダウンに "PHP"の値が表示されます。データベースで別のオプションからドロップダウン値を設定する
*編集
AJAX
を使用して別のドロップダウン値からSetドロップダウンオプション*ここでは、Ajaxの機能
<script type="text/JavaScript">
function Intake()
{
$.ajax({
type: "POST",
url: "IntakeDropdown.php",
//data: { id_option: $(object).val(), operation: 'get_subjects' },
contentType ="application/json; charset=utf-8",
dataType: "json",
success: function(data)
{
//Clear options corresponding to earlier option of first dropdown
//$('#Iname').empty();
$('#Iname').html("<option> value='0'>--Select Intake--</option>");
//Populate options of the second dropdown
$.each(data, function(i,item)
{
$('#Iname').html('<option value="'+ data[i].id+'">'+ data[i].name+'</option>');
});
//$('#Iname').focus();
},
complete: function(){
}
});
}
function Courses(sid)
{
$.ajax({
type: "POST",
url: "CoursesDropdown.php?sid="+sid,
//data: { id_option: $(object).val(), operation: 'get_subjects' },
contentType ="application/json; charset=utf-8",
dataType: "json",
success: function(data)
{
//Clear options corresponding to earlier option of first dropdown
//$('#Courses').empty();
$('#Courses').html("<option> value='0'>--Select Courses--</option>");
//Populate options of the second dropdown
$.each(data, function(i,item)
{
$('#Courses').html('<option value="'+ data[i].id+'">'+ data[i].name+'</option>');
});
//$('#Courses').focus();
},
complete: function(){
}
});
}
$(document).ready(function(){
Intake();
$("#Iname").change(function(){
var intakeid = $("#Iname").val();
Courses(intakeid);
});
});
</script>
</head>
にIntakeDropdown.phpさ
<?php
include "connect.php";
$checkuser = "Select * from Intake";
$result2 = mysqli_query($con, $checkuser);
if (mysqli_num_rows($results2)) {
$data = array();
while ($row = mysqli_fetch_array($results2)) {
$data[] = array(
'id' => $row['IntakeID'],
'name' => $row['IntakeName'],
);
}
header('Content-type: application/json');
echo json_encode($data);
}
?>
CoursesDropdown
<?php
include "connect.php";
$checkuser = "Select * from courses Where IntakeID ='" . $_GET("sid") . "'";
$result2 = mysqli_query($con, $checkuser);
if (mysqli_num_rows($results2)) {
$data = array();
while ($row = mysqli_fetch_array($results2)) {
$data[] = array(
'id' => $row['CoursesID'],
'sid' => $row['IntakeID'],
'name' => $row['CoursesName'],
);
}
header('Content-type: application/json');
echo json_encode($data);
}
?>
[フォームのサンプル(http://imgur.com/iIUg6WD) –
偽造が – Saty
質問ビット不明であるセット、より多くの情報を追加しよう。 –