0

MySQL我像这样打印行loop

$list_students = mysql_query(
"SELECT 
    s.student_id, s.student_firstname, s.student_lastname, s.isActive, 
    c.city_name,
    sd.student_startdate, sd.student_enddate
        FROM students s 
            INNER JOIN cityselections c ON c.city_id = s.student_city_id
            INNER JOIN studentdates sd ON sd.student_id = s.student_id
                WHERE s.student_city_id NOT LIKE '1'");

while ($row = mysql_fetch_array($list_students)) 
{
    echo "<tr>\n";
        echo "<td>" . $row['student_lastname'] . ",  " . $row['student_firstname'] ."</td>\n";
        echo "<td>" . $row['student_startdate'] . "</td>\n";
        echo "<td>" . $row['student_enddate'] . "</td>\n";          
    echo "</tr>\n";
}

我也有这个function

function calculateNextDate($startDate, $days)
{
        $dateTime = new DateTime($startDate);

        while($days) {
            $dateTime->add(new DateInterval('P1D'));    

            if ($dateTime->format('N') < 6) {
                $days--;
            }
        }

        return $dateTime->format('Y-m-d');
}

给定开始日期和数字,Wich 计算日期,不包括周末。例如:

calculateNextDate ($list_students['student_startdate'],15)

现在我希望这个函数在while循环中工作,使用另一个可以为每个返回多行的MySQL查询:student_id

SELECT scp.cpl_id, scp.student_id, SUM(scpe.scpe_estimated_days) AS total FROM studentcourseplan scp
    INNER JOIN studentcourseplanelements scpe ON scpe.scpe_cpl_id = scp.cpl_id
            GROUP BY scp.cpl_id

这可以输出:

+--------+------------+-------+
| cpl_id | student_id | total |
+--------+------------+-------+
|    195 |         34 |    74 |
|    204 |         85 |   153 |
|    205 |         85 |   199 |
|    206 |         65 |    11 |
+--------+------------+-------+

我需要该函数来计算内部输出的最大数量loop并打印此输出的日期

.. 对于每个学生 ( student_id)。

如何才能做到这一点?

4

0 回答 0