我正在爲5人的日常使用製作一個小型預約時間表。我現在面臨的唯一問題是讓時間表顯示同一員工的所有約會成一列。到目前爲止,我嘗試了一些不同的方法,但沒有運氣。我會發布我得到的最好的兩次嘗試。將mysql記錄從一個設定日期合併到一個時間表中?
下面是我從第一次嘗試寫的代碼中得到的輸出示例。
http://jsfiddle.net/yy885/CXcjR/2/
它單獨顯示被任命爲這個輸出的查詢是在指定的日期,工作人員只是正常查詢。我的問題是我無法找到合併這3條記錄的方法,並將其輸出到本時間表的一列中。就目前而言,如果我爲他們每個人安排了5次約會,那麼這將顯示25條記錄(25列),這不會很好。根據我目前爲止的代碼,我可以想到一個快速解決方法,但我不喜歡使用它。一次只能顯示一名工作人員。但這種方式對於打算約會的女孩來說很困難,因爲她可能會忽略時間表,並錯誤地向顧客發出日期/時間。
<?php
include("connect.php");//connect to the database.
//$todaydate = date('m/d/Y');
$todaydate = "11/22/2013";
$staffd = "Jerry";
$query = mysql_query('SELECT * FROM appointment2 where date="'.$todaydate.'" AND staff="'.$staffd.'"');
$num_row = mysql_num_rows ($query);
if ($num_row > 0) {
$i=0;
while($i < $num_row){
$date = mysql_result($query,$i,"date");
$clientid = mysql_result($query,$i,"clientid");
$staff = mysql_result($query,$i,"staff");
$status = mysql_result($query,$i,"status");
$paid = mysql_result($query,$i,"paid");
$comment = mysql_result($query,$i,"comment");
$t0900 = mysql_result($query,$i,"0900");
$t0915 = mysql_result($query,$i,"0915");
$t0930 = mysql_result($query,$i,"0930");
$t0945 = mysql_result($query,$i,"0945");
$t1000 = mysql_result($query,$i,"1000");
$t1015 = mysql_result($query,$i,"1015");
$t1030 = mysql_result($query,$i,"1030");
$t1045 = mysql_result($query,$i,"1045");
$t1100 = mysql_result($query,$i,"1100");
$t1115 = mysql_result($query,$i,"1115");
$t1130 = mysql_result($query,$i,"1130");
$t1145 = mysql_result($query,$i,"1145");
$t1200 = mysql_result($query,$i,"1200");
$t1215 = mysql_result($query,$i,"1215");
$t1230 = mysql_result($query,$i,"1230");
$t1245 = mysql_result($query,$i,"1245");
$t1300 = mysql_result($query,$i,"1300");
$t1315 = mysql_result($query,$i,"1315");
$t1330 = mysql_result($query,$i,"1330");
$t1345 = mysql_result($query,$i,"1345");
$t1400 = mysql_result($query,$i,"1400");
$t1415 = mysql_result($query,$i,"1415");
$t1430 = mysql_result($query,$i,"1430");
$t1445 = mysql_result($query,$i,"1445");
$t1500 = mysql_result($query,$i,"1500");
$t1515 = mysql_result($query,$i,"1515");
$t1530 = mysql_result($query,$i,"1530");
$t1545 = mysql_result($query,$i,"1545");
$t1600 = mysql_result($query,$i,"1600");
$t1615 = mysql_result($query,$i,"1615");
$t1630 = mysql_result($query,$i,"1630");
$t1645 = mysql_result($query,$i,"1645");
$t1700 = mysql_result($query,$i,"1700");
$t1715 = mysql_result($query,$i,"1715");
$t1730 = mysql_result($query,$i,"1730");
$t1745 = mysql_result($query,$i,"1745");
$t1800 = mysql_result($query,$i,"1800");
$t1815 = mysql_result($query,$i,"1815");
$t1830 = mysql_result($query,$i,"1830");
$t1845 = mysql_result($query,$i,"1845");
$t1900 = mysql_result($query,$i,"1900");
$t1915 = mysql_result($query,$i,"1915");
$t1930 = mysql_result($query,$i,"1930");
$t1945 = mysql_result($query,$i,"1945");
$t2000 = mysql_result($query,$i,"2000");
$t2015 = mysql_result($query,$i,"2015");
$t2030 = mysql_result($query,$i,"2030");
$t2045 = mysql_result($query,$i,"2045");
echo '<table border="1">';
echo '<tr><td style="word-wrap: break-word">'.$date.'</td></tr>';
echo '<tr><td style="word-wrap: break-word"> '.$staff.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t0900.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t0915.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t0930.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t0945.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1000.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1015.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1030.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1045.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1100.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1115.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1130.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1145.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1200.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1215.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1230.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1245.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1300.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1315.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1330.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1345.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1400.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1415.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1430.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1445.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1500.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1515.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1530.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1545.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1600.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1615.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1630.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1645.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1700.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1715.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1730.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1745.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1800.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1815.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1830.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1845.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1900.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1915.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1930.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t1945.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t2000.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t2015.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t2030.'</td></tr>';
echo '<tr><td style="word-wrap: break-word">'.$t2045.'</td></tr>';
echo '</table>';
++$i; } } else { echo "No record found"; }
?>
其次嘗試。 我只用日期,時間,人員和事件來重寫mysql。我使用concat將時間和事件放入一個字符串中。所以我用的查詢只是調用這個日期和工作人員的名字。然後我把這些結果放入一個數組中並提取它們。
這是結果。
0945 Event A part 1
1115 Event A part 2
1315 Event B part 1
1630 Event B part 2
1745 Event B part 3
1900 Event C part 1
1945 Event C part 2
2015 Event B part 4
但是後來我不知道該怎麼做才能很好地把它們放入時間表。我可以把它們放在桌子上,但不會顯示那些空的插槽,這將使它難以閱讀。
下面是我用於此嘗試的代碼。
<?php
include("connect.php");//connect to the database.
$todaydate = "11/22/2013";
$staffd = "Jerry";
$query = 'SELECT CONCAT(time," ",event) FROM appointment3 where date="'.$todaydate.'" AND staff="'.$staffd.'"';
$result = mysql_query($query) or die ("no query");
$result_array = array();
while($row = mysql_fetch_assoc($result))
{
$new_arr[] = $row['CONCAT(time," ",event)'];
}
sort($new_arr);
foreach ($new_arr as $value) {
echo $value."<br />\n";
}
?>
任何建議,歡迎,因爲我仍然認爲我的方式不會很好地工作......
感謝您的幫助!我明白了它現在的工作原理!現在唯一的問題是我確實很好地將它插入表中,但這些Array([0] =>'[1] => [2] =>'[3] =>'.....')仍然存在。 ..有什麼辦法可以刪除它們嗎?再次感謝。 –