预定科目的时间表

时间:2016-01-28 14:09:05

标签: php css arrays

我说得对,虽然我现在的问题是如何在表格行中放置一个样式,其中包含数据,如果我可以将行数放入其中以便它看起来像一个表格行,那就更好了。“ p>

这是输出:

enter image description here

这是我的代码:



<?php
	$db = new mysqli("localhost", "root", "", "bsu_db");
	if($db->connect_errno > 0){
	    die('Unable to connect to database [' . $db->connect_error . ']');
	}	
	$times = ["7:00:00", "7:30:00", "8:00:00", "8:30:00", "9:00:00", "9:30:00", "10:00:00", "10:30:00", "11:00:00", "11:30:00", "12:00:00"];
	$days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
	$SubjDay = array();
	$sqlSubjDay = "SELECT * FROM subject_day_tbl";
	$qrySubjDay = $db->query($sqlSubjDay);
	while($rowSubjDay = $qrySubjDay->fetch_assoc()){
		//array_push($SubjDay, $rowSubjDay['sub_day'], $rowSubjDay['start_time'], $rowSubjDay['end_time']);
		$SubjDay[] = $rowSubjDay;
	}
	json_encode($SubjDay);
?>
<table class="table table-bordered table-condensed">
	<thead>
		<tr>
			<th></th>
			<?php
				foreach ($days as $day ) {
					echo "<th>$day</th>";
				}
			?>
		</tr>
	</thead>
	<tbody>
	<?php	
		foreach ($times as $time) {						
	?>
	<tr>	
		<td><?php echo $time; ?></td>
		<?php
			foreach ($days as $day) {											
				echo "<td>";
				foreach($SubjDay as $sd){
											
					if($day == $sd['sub_day'] && strtotime($time) >= strtotime($sd['start_time']) && strtotime($time) <= strtotime($sd['end_time'])){
						echo $sd['sub_day'] , " " , $sd['start_time'] , " - " , $sd['end_time'];
					}
											
				}
				echo "</td>";
			}

		?>
	</tr>
	<?php 		
		} 
	?>					
	</tbody>
</table>
&#13;
&#13;
&#13;

0 个答案:

没有答案