$timelist = array(540, 570, 600, 630, 660, 690, 780, 810, 840, 870, 900, 930, 960, 990, 1020); $list = array("予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可"); $list1 = array("予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可"); $list2 = array("予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可"); $charge = array('松島','小野','草野'); foreach($result as $value){ if($value['charge'] == $charge[0]){ for($i=0; $i < count($timelist); $i++){ if($timelist[$i] >= $value['time1'] and $timelist[$i] < $value['time2']){ $list[$i] = "×"; } } } elseif($value['charge'] == $charge[1]){ for($i=0; $i < count($timelist); $i++){ if($timelist[$i] >= $value['time1'] and $timelist[$i] < $value['time2']){ $list1[$i] = "×"; } } }elseif($value['charge'] == $charge[2]){ for($i=0; $i < count($timelist); $i++){ if($timelist[$i] >= $value['time1'] and $timelist[$i] < $value['time2']){ $list2[$i] = "×"; } } } } ?> <style> #tbl-bdr table,#tbl-bdr td,#tbl-bdr th { border-collapse: collapse; border: 1px solid #000000; } table td{ width:45px; } </style> <br> <div id="tbl-bdr"> <table> <tr> <td></td><td>9:00~</td><td>9:30~</td><td>10:00~</td><td>10:30~</td><td>11:00~</td><td>11:30~</td><td>13:00~</td><td>13:30~</td><td>14:00~</td><td>14:30~</td><td>15:00~</td><td>15:30~</td><td>16:00~</td><td>16:30~</td><td>17:00~</td> </tr> <tr> <td><?php echo $charge[0]; ?></td> <?php foreach($list as $value){ echo "<td>". $value."</td>"; } ?> </tr> <tr> <td><?php echo $charge[1]; ?></td> <?php foreach($list1 as $value){ echo "<td>". $value."</td>"; } ?> </tr> <tr> <td><?php echo $charge[2]; ?></td> <?php foreach($list2 as $value){ echo "<td>". $value."</td>"; } ?> </tr> </table>
表示はこれでほぼOK(最終版は、現在時刻以降を表示したい)なんだが、これ、どうやって書くんだ??
あ、$listはfor文の中に書いて、かつ、tdもfor文で回すのか???
名前ごとにforeachを回す仕様に書き換えました。
<style> #tbl-bdr table,#tbl-bdr td,#tbl-bdr th { border-collapse: collapse; border: 1px solid #000000; } table td{ width:45px; } </style> <br> <div id="tbl-bdr"> <table> <tr> <td></td><td>9:00~</td><td>9:30~</td><td>10:00~</td><td>10:30~</td><td>11:00~</td><td>11:30~</td><td>13:00~</td><td>13:30~</td><td>14:00~</td><td>14:30~</td><td>15:00~</td><td>15:30~</td><td>16:00~</td><td>16:30~</td><td>17:00~</td> </tr> <?php $charge = array('松島','小野','草野'); foreach($charge as $value){ echo "<tr><td>".$value. "</td>"; $timelist = array(540, 570, 600, 630, 660, 690, 780, 810, 840, 870, 900, 930, 960, 990, 1020); $list = array("予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可","予約可"); foreach($result as $result1){ if($result1['charge'] == $value){ for($i=0; $i < count($timelist); $i++){ if($timelist[$i] >= $result1['time1'] and $timelist[$i] < $result1['time2']){ $list[$i] = "×"; } } } } foreach($list as $value){ echo "<td>".$value."</td>"; } echo "</tr>"; } ?> </table>
お!
formから草野さんに予約を入れます。
WoW!
次は、本日出勤の担当者のみ表示できるようにしたいですね。
mysql側で欠勤スケジュールのテーブルおよびdatepickerのformをつくります。