if(isset($_POST['submit'])) {
$doc = new Doc_Schedule();
$doc->doctor = $_POST['doctor'];
$doc->department = $_POST['dpt'];
$doc->sheduledate = $_POST['date'];
$doc->scheduletime = $_POST['time'];
if( $doc->create() ) {
$message = "Doctors Information Saved Successfully";
} else {
$message = join("<br/>",$doc->errors);
}
}
<select name="doctor" id="Deptmentselectbox" class="AllSelectBoxes">
<option value="">Select Doctor</option>
<?php
$sql = "SELECT `fullname`,`depid`,`docid` FROM `doctors` ORDER BY fullname ASC";
$result = $database->query($sql) or die('cannot connect to the database');
while( $row = mysql_fetch_array($result) ) {
echo"<option value= ".$row['docid'].">".$row['fullname']."</option>";
}
?>
</select>
我有一个选择框,可以在桌子上显示医生。当我点击某位医生时,我想将doctors.docid
和doctors.deptid(department id)
发送给某个班级进行进一步处理。
我无法找到解决方案,除了为部门ID创建新的选择框。
答案 0 :(得分:0)
将两个值与选项值中的分隔符组合:
echo"<option value= \"{$row['docid']}|{$row['depid']}\">{$row['fullname']}</option>";
并在提交后分隔值:
list($docid,$depid)=explode('|',$_POST['doctor']);
或者,如果您只使用docid
,则会从数据库中获得depid
。
顺便说一句,请停止使用mysql_*
,因为它已弃用,请转到mysqli_*
或PDO
!
答案 1 :(得分:0)
我会用这样的分隔符对值进行编码:
echo"<option value= ".$row['docid'].";".$row['deptid'].">".$row['fullname']."</option>";
然后你只需要在函数中调用explode:
list($docid, $deptid) = explode($_POST['doctor'], ";");
答案 2 :(得分:0)
我的建议是使用PHP连接然后分离值。
<select name="doctor" id="Deptmentselectbox" class="AllSelectBoxes">
<option value="<?php echo "$doc['doctor']^$doc['department']"; ?> ">Select Doctor</option>
然后处理时:
$doc = explode("^", $_POST['doctor']);
$doctor = $doc['0'];
$department = $doc['1'];
这样的东西会通过一个帖子对象发送多个值。
答案 3 :(得分:0)
您可以使用逗号分隔值:
echo "<option value=".$doc['docid'].",".$doc['depid']; ?>">".$row['fullname']."</option>"
可以在服务器上解析为
ID = explode($_POST['doctor'], ",");
或者您可以使用HTML5数据属性。
echo "<option value=".$doc['docid']." data-DepId=".$doc['depid'].">".$row['fullname']."</option>"