2016-09-16 78 views
-1

我正在開展醫生預約系統,其中醫生將首先進入開始時間和結束時間,如上午10:00至下午6:00。如果用戶想要預約醫生它會按照預定時間顯示。我想以30分鐘的時間間隔顯示時間,例如10:00 - 10:30,10:30-11:00。結束時間。它將從數據庫中選擇開始時間和結束時間。我怎樣才能做到這一點?我想要顯示30分鐘的時間間隔/

+0

你到目前爲止嘗試過什麼?請分享您的代碼。你正在使用哪個數據庫? –

+0

那麼最新的問題?只需用你需要的數據創建簡單的html選擇。 – DEADMC

+0

堆棧溢出不是代碼寫入服務。請勿要求我們爲您編寫代碼。 – roberto06

回答

0

僞代碼:

do connection to database 
get result from database with start and endtime 

new array 

while startTime is not equal to endTime 
    startTime + 30 minutes 

    insert into array startTime 
while end 

generate selectbox with array values 

show selectbox 

這是你如何能做到這一點。

1

你必須使用strtotime才能達到你想要的。

$starttime = '9:00'; // your start time 
$endtime = '21:00'; // End time 
$duration = '30'; // split by 30 mins 

$array_of_time = array(); 
$start_time = strtotime ($starttime); //change to strtotime 
$end_time  = strtotime ($endtime); //change to strtotime 

$add_mins = $duration * 60; 

while ($start_time <= $end_time) // loop between time 
{ 
    $array_of_time[] = date ("h:i", $start_time); 
    $start_time += $add_mins; // to check endtie=me 
} 

輸出可以使用貝洛代碼獲得。

echo '<pre>'; 
print_r($array_of_time); 
echo '</pre>'; 

對於上面的代碼的輸出將是這樣的。

Array 
(
    [0] => 09:00 
    [1] => 09:30 
    [2] => 10:00 
    [3] => 10:30 
    [4] => 11:00 
    [5] => 11:30 
    [6] => 12:00 
    [7] => 12:30 
    [8] => 01:00 
    [9] => 01:30 
    [10] => 02:00 
    [11] => 02:30 
    [12] => 03:00 
    [13] => 03:30 
    [14] => 04:00 
    [15] => 04:30 
    [16] => 05:00 
    [17] => 05:30 
    [18] => 06:00 
    [19] => 06:30 
    [20] => 07:00 
    [21] => 07:30 
    [22] => 08:00 
    [23] => 08:30 
    [24] => 09:00 
) 
+0

@Rahul Pamnani。如果您在使用我的代碼時遇到任何障礙,請告訴我。 –

+0

非常感謝。但問題是我想在表格中顯示這個時間,比如9:00 - 9:30。下一排9:30至10:00。請幫助。@ Naresh Kumar.P –

+0

@RahulPamnani。我先回答你的問題。現在,這是你的額外問題,你得到了輸出後,你是在等待。你應該讚揚這個答案,一旦你有了信用,我們將討論這個問題。因爲所有人都想分享基於SO中的學分的知識。 –

相關問題