我有一个称为fundedCourses的MS SQL表,该表具有许多字段,crsode,crsName等。我希望能够选择一个crsName,然后具有其他具有关联值的输入字段,例如crsCode。这两个字段都不是主键。
我尝试使用SELCT FROM WHERE函数,但不确定如何在crsCode php中引用crsName。
<?php
//Ensures connection to database
include_once 'dbConnect.php';
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form name="costing">
Course name
<select name="Course Name" id="crsName" class="form-control">
<option> Select </option>
<?php
$sql = "SELECT crsName FROM fundedCourses";
$result = sqlsrv_query($conn,$sql) or die("Couldn't execute query");
while ($data=sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){
echo '<option value="'.$data['crsName'].'">';
echo $data['crsName'];
echo "</option>";
}
?>
</select></br></br>
Course code
<?php
var $crsName = crsName;
$sql ="SELECT crsName FROM fundedCourses WHERE crsName = $crsName"
$result = sqlsrv_query($conn,$sql) or die("Couldn't execute query");
while ($data=sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){
echo '<input type="text" name="crsCode" class="form-control" id="crsCode">';
echo $data['crsCode'];
}
?>
</form>
</body>
</html>
When I pick a crsName I want the associated crsCode to populate the input field.
当我选择一个crsName时,我希望关联的crsCode填充输入字段。