0
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.dociddoctors.deptid(department id)一个班级以进行进一步处理。

我在为部门 ID 创建新选择框的情况下找不到其他解决方案。

4

4 回答 4

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'];

类似的东西会通过一个 post 对象发送多个值。

于 2013-03-09T20:41:23.403 回答
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>"
于 2013-03-09T20:42:42.560 回答
0

将两个值与选项值中的分隔符结合起来:

echo"<option value= \"{$row['docid']}|{$row['depid']}\">{$row['fullname']}</option>";

并在提交后分隔值:

list($docid,$depid)=explode('|',$_POST['doctor']);

或者,如果您只使用docid,您depid将从您的数据库中获取。

而且,顺便说一句,停止使用,mysql_*因为它已被弃用,移至mysqli_*or PDO

于 2013-03-09T20:36:27.997 回答
0

我会用这样的分隔符对值进行编码:

  echo"<option value= ".$row['docid'].";".$row['deptid'].">".$row['fullname']."</option>";

然后你只需在函数中调用explode:

  list($docid, $deptid) = explode($_POST['doctor'], ";");
于 2013-03-09T20:38:07.493 回答