2012-11-08 65 views
1

我正在爲醫生辦公室構建一個位置查找器應用程序。在應用程序中,有多個病人的等待列表中進行檢查。使用mysql進行ajax更新的問題

例如,第一個病人是病人X.這裏是循序漸進的過程(形容我的問題最簡單的方法)

1)在患者X的名字旁邊有一個標記爲的按鈕。簽入。點擊簽入後,患者ID(稱爲selectid)通過Ajax發送至changeloc.php登記入住時間和日期。

2)成功後,用戶將看到一個下拉列表(替換初始按鈕),並帶有用戶可以選擇的多個位置。從選擇中選擇一個位置後,變量locationSelect將發送到changeloc.php它將在那裏記錄。然後

3)用戶可能決定選擇多個位置,重複步驟2

4)最後,當用戶進行選擇的地點,他點擊在相同的最後一個選項中選擇其中用戶在第2步和第3步中點擊了位置,標題爲檢出。一旦點擊這個,它被髮送到checkloc.php並記錄下來。

5)最後,下拉自敗的一句簽出

這裏是我的代碼:

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)數據庫沒有被任何東西更新。

感謝您的幫助!如果您需要更多信息,請詢問詳情。

+0

我檢查了Chrome控制檯中的錯誤,但似乎沒有任何 – Muhambi

+0

我認爲在同一選擇中籤出檢查選項與檢查位置有點危險。用戶很可能無意中點擊了Check Out,而不是考試室4.在開始時顯示位置下拉列表和Check in按鈕時,當用戶點擊登記時,您會不會更容易有你需要檢查他們的所有數據。之後,您可以隱藏下拉菜單,只需將檢入按鈕更改爲結帳按鈕,然後重新綁定點擊方式即可執行結帳。 – samazi

+0

@sandor謝謝你會做 – Muhambi

回答

1

代碼$e.nextAll('form').first().find('.location').show();正在尋找一個類爲「location」的元素,而html中的表單有一個類爲「locationSelect」的選擇。我想你想讓這兩個班讀同一個。