【发布时间】:2017-05-04 22:34:15
【问题描述】:
我的项目中有一个模块,它是关于在课堂时间表中寻找空闲位置的。我正在从数据库中毫无问题地获取变量。我需要一个数组,它是所有教室的返回值,这是我在 DB 中有多少个教室。这个教室也有可变的时间段 1 到 12 并且每个时间段都有持续时间,例如,如果我在第 4 阶段 3 持续时间它应该写 1 2 3 xxx 7 8 9 10 11 12 并且如果我在第 9 阶段 2 持续时间它有另一门课程应该是 1 2 3 xxx 7 8 xx 11 12。如果我在查询中给出 class_no,我会在一维数组中完成。但它应该不仅仅是一个教室。它仅在 1 行中显示数字 1..12。
$dayy = $_GET['src_day0'];
$drt = $_GET['src_duration0'];
$tm = $_GET['src_time0'];
$faculty_id = $_SESSION['faculty_id'];
$scale = "select DISTINCT t.class_no,t.time,t.duration from ttable t,class c where
day='$dayy' AND (t.faculty='$faculty_id' OR c.faculty='$faculty_id')";
$result = $conn->query($scale);
$x = 1;
while ($rows = $result->fetch_assoc()) {
$class = $rows['class_no'];
$arr = array(
array($x => "$class"),
array(
1 => " 1 ", 2 => " 2 ", 3 => " 3 ", 4 => " 4 ", 5 => " 5 ", 6 => " 6 ",
7 => " 7 ", 8 => " 8 ", 9 => " 9 ", 10 => " 10 ", 11 => " 11 ", 12 => " 12 ",
));
$x++;
}
while ($rows = $result->fetch_assoc()) {
$time = $rows['time'];
$duration = $rows['duration'];
$result1 = ($time + $duration);
for($j=1;$j<$x;$j++)
for ($i = $time; $i < $result1; $i++)
$arr[$j][$i] = "x1";
}
}
for ($i = 1; $i < $x; $i++) {
for ($j = 1; $j < 13; $j++)
echo $arr[$i][$j];
echo "</br>";
【问题讨论】:
-
请添加一个更好的标题来真正解释您的问题。
标签: php mysql sql arrays multidimensional-array