我有一个包含 7 列的 (Examdata) 表:
(Class_ID、Subject_ID、Student_ID、Subject_name、exam_days、exam_dates、exam_times)
我想检测第二天有考试和另一场考试的“student_id”,例如:
| student_id | subject_name | exam_days | exam_date |
|------------|--------------|-----------|-----------|
| 1 | math | Sunday | 2/4/2019 |
| 1 | physical | Monday | 3/4/2019 |
这里的 student_id="1" 连续几天有两次考试,也许 student_id 比我想检测的还要多。
注意:如果学生在周四 m 和周日有考试,则不应考虑,因为他们之间是周末。
这是我的尝试:
<?php
$con = mysqli_connect("localhost", "root", "", "Exams");
$array1 = array();
$n = "SELECT DISTINCT exam_dates FROM Examdata ORDER BY exam_dates";
$queryarray1 = mysqli_query($con, $n) or die("Error in query: $queryarray1. ".mysqli_error());
while ($row = mysqli_fetch_assoc($queryarray1)) {
$array1[] = $row;
}
// print_r($array1);
/* the output for this :
Array ( [0] => Array ( [exam_dates] => 1440-04-02 ) [1] => Array ( [exam_dates] => 1440-04-03 ) [2] => Array ( [exam_dates] => 1440-04-04 ) [3] => Array ( [exam_dates] => 1440-04-05 ) [4] => Array ( [exam_dates] => 1440-04-06 ) [5] => Array ( [exam_dates] => 1440-04-08 ) [6] => Array ( [exam_dates] => 1440-04-09 ) [7] => Array ( [exam_dates] => 1440-04-10 ) [8] => Array ( [exam_dates] => 1440-04-11 ) [9] => Array ( [exam_dates] => 1440-04-12 ) [10] => Array ( [exam_dates] => 1440-04-13 ) [11] => Array ( [exam_dates] => 1440-04-15 ) [12] => Array ( [exam_dates] => 1440-04-16 ) [13] => Array ( [exam_dates] => 1440-04-17 ) [14] => Array ( [exam_dates] => 1440-04-18 ) [15] => Array ( [exam_dates] => 1440-04-20 ) )
*/
$b = json_encode($array1);
$z = sizeof($array1);
for ($i = 0; $i < $z; $i++) {
$search = "SELECT *
FROM Examdata e1
(
SELECT *
}
}
消息错误:
查询错误:。您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以获取在第 2 行附近使用的正确语法(SELECT * from Examdata e2 where e1.exam_dates==[ && e2.exam_dates='
-- 但我不知道如何在查询中传递数组。
莫回无
潇湘沐