我有一个似乎没有获取第二行 ID 的 SQL 查询。我该如何解决?
$sql = "SELECT
*
FROM ts_request
INNER JOIN ts_day
ON ts_request.day_id = ts_day.id
INNER JOIN ts_period
ON ts_request.period_id = ts_period.id
INNER JOIN ts_allocation
ON ts_request.id = ts_allocation.request_id
WHERE ts_request.round=:round
AND ts_request.dept_id=:dept
ORDER BY ts_request.module_id ASC";
}
$stm = $pdo->prepare( $sql );
$stm->execute( array( ':round' => 'P', ':dept' => $loggedin_id ) );
$rows = $stm->fetchAll();
foreach ($rows as $row)
{
$row_id = $row['id'];
echo '<tr align="center">';
echo '<td>'.$row['module_id'].'</td>';
echo '<td>'.$row['day'].'</td>';
echo '<td>'.$row['period'].'</td>';
echo '<td>';
$sql = "SELECT
*
FROM ts_roompref
WHERE request_id=:request_id";
$stm = $pdo->prepare( $sql );
$stm->execute( array( ':request_id' => $row_id ) );
$rows = $stm->fetchAll();
foreach ($rows as $row)
{
if ($row['room_id']!="0")
echo $row['room_id'].'<br>';
}
echo '</td>';
echo '<td>';
$sql = "SELECT
*
FROM ts_allocation
WHERE request_id=:request_id";
$stm = $pdo->prepare( $sql );
$stm->execute( array( ':request_id' => $row_id ) );
$rows = $stm->fetchAll();
foreach ($rows as $row)
{
echo $row['status'];
}
echo '</td></tr>';
};