我正在为医生办公室构建位置查找器应用程序。在应用程序中,有多个等待登记的患者的列表。
例如,第一个病人是病人 X。这是一步一步的过程(描述我的问题的最简单的方法)
1) 患者 X 的姓名旁边是一个标记为Check In的按钮。单击 Check In 后,患者 ID(称为 selectid)通过 Ajax 发送到changeloc.php,其中记录了检查时间和日期。
2) 成功后,用户会看到一个下拉菜单(替换初始按钮),其中包含用户可以选择的多个位置。从 select 中选择一个位置后,变量locationSelect将被发送到changeloc.php并在其中记录。
3)然后用户可能决定选择多个位置,重复步骤 2
4) 最后,当用户完成位置选择时,他点击用户在步骤 2 和 3 中点击位置的同一选择中的最后一个选项,标题为Check Out。单击此按钮后,它将被发送到checkloc.php并记录。
5) 最后,下拉菜单消失,Checked Out字样
这是我的代码:
PHP
<?php
date_default_timezone_set('America/Denver');
$apptid = $_REQUEST['selectid'];
$currentlocation = $_REQUEST['locationSelect'];
$currentlocationstart = date("Y-m-d H:i:s");
$checkin = $_REQUEST['checkIn'];
$checkout = $_REQUEST['checkOut'];
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = '***********';
/*** mysql password ***/
$password = '**********';
$conn = new PDO("mysql:host=$hostname;dbname=sv", $username, $password);
/*** The SQL SELECT statement ***/
if(!empty($currentlocation)){
//$sql2 = "UPDATE history SET ";
//$query = $conn->prepare($sql2);
//$query->execute(array(':apptid'=>$apptid, ':locationstart'=>$locationstart));
$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($currentlocation,$currentlocationstart, $apptid));
}
if(!empty($checkin)){
$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($checkin,$currentlocationstart, $apptid));
//$sql2 = "insert into history (apptid, locationstart) VALUES (:apptid,:locationstart)";
//$query = $conn->prepare($sql2);
//$query->execute(array(':apptid'=>$apptid, ':locationstart'=>$locationstart));
}
if(!empty($checkout)){
$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($checkout,$currentlocationstart, $apptid));
}
?>
Javascript
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.locationSelect').hide(); // Hide all Selects on screen
$('.finished').hide(); // Hide all checked Out divs on screen
$('.checkIn').click(function() {
var $e = $(this);
var data = $e.data("param").split('-')[1] ;
// gets the id of button (1 for the first button)
// You can map this to the corresponding button in database...
$.ajax({
type: "POST",
url: "changeloc.php",
// Data used to set the values in Database
data: { "checkIn" : $(this).val(), "buttonId" : data},
success: function() {
// Hide the current Button clicked
$e.hide();
// Get the immediate form for the button
// find the select inside it and show...
$e.nextAll('form').first().find('.location').show();
}
});
});
$('.locationSelect').change(function() {
$e = $(this);
var data = $e.data("param").split('-')[1] ;
// gets the id of select (1 for the first select)
// You can map this to the corresponding select in database...
$.ajax({
type: "POST",
url: "changeloc.php",
data: { "locationSelect" : $(this).val(), "selectid" : data},
success: function() {
// Do something here
}
});
});
$('.locationSelect option[value="CheckOut"]').click(function() {
var $e = $(this);
var data = $e.closest('select').data("param").split('-')[1] ;
// gets the id of select (1 for the first select)
// You can map this to the corresponding select in database...
// from which checkout was processed
$.ajax({
type: "POST",
url: "changeloc.php",
data: { "checkOut" : $(this).val(), "selectid" : data},
success: function() {
// Get the immediate form for the option
// find the first finished div sibling of form
// and then show it..
$e.closest('form').nextAll('.finished').first().show();
// Hide the current select in which the option was selected
$e.closest('.locationSelect').hide();
alert('done');
},
error: function(request) {
alert(request.responseText);
}
});
});
});
</script>
和html:
<button class="checkIn" data-param="button-1">Check In</button>
<form method='post' class='myForm' action=''>
<select name='locationSelect' class='locationSelect' data-param="location-1">
<option value='1'>Exam Room 1</option>
<option value='2'>Exam Room 2</option>
<option value='3'>Exam Room 3</option>
<option value='4'>Exam Room 4</option>
<option value='CheckOut'>Check Out</option>
</select>
</form>
<div class='finished' style='color:#ff0000;'>Checked Out</div>
问题是:
1)当用户单击“签入”按钮时,该按钮会像应有的那样消失,但没有出现下拉菜单(这可能意味着下拉菜单后不会出现其他任何内容)
2)数据库没有更新任何东西。
感谢您的任何帮助!如果您需要更多,请询问详细信息!