html 테이블 행이 제대로 표시되지 않습니다. 테이블 행에서 두 개의 while 루프를 결합하고 싶지만 슬프게도 업데이트 및 삭제 버튼이 제대로 정렬되지 않았습니다.
여기에 두 개의 쿼리를 사용한 코드가 있습니다. 그래서 두 개의 while 루프가 있습니다.
$sql_sel=mysql_query("SELECT students.stud_id, students.fname, students.lname, students.gender, subjects.sub_code, subjects.subject_name FROM students, enrollments, subjects WHERE students.stud_id = enrollments.stud_id and subjects.sub_code = enrollments.sub_code");
$sql_sel1=mysql_query("SElECT * FROM enrollments");
while($row=mysql_fetch_array($sql_sel)) //for the first query
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['stud_id'];?></td>
<td><?php echo $row['fname']." ".$row['lname'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['sub_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<?php
while($row=mysql_fetch_array($sql_sel1)) //for the second query
{ <!-------The Update and Delete Button are not displayed properly------>
?>
<td align="center"><a href="?tag=enrollment_entry&opr=upd&rs_id=<?php echo $row['enroll_num'];?>" title="Update"><img src="picture/update.png" /></a></td>
<td align="center"><a href="?tag=view_enrollments&opr=del&rs_id=<?php echo $row['enroll_num'];?>" title="Delete"><img src="picture/delete.png" /></a></td>
<?php
}
?>
</tr>
<?php
}
?>
다음은 문제의 시각적 시나리오입니다.
원하는 출력은 다음과 같아야합니다.
이 시도,
$sql= "SELECT sts.stud_id, sts.fname, sts.lname, sts.gender, sub.sub_code, sub.subject_name, ets.enroll_num
FROM students sts
JOIN enrollements ets ON(sts.stud_id = ets.stud_id)
JOIN subjects sub ON (sub.sub_code = ets.sub_code)
GROUP BY sts.stud_id, sub.sub_code";
$sql_sel=mysql_query($sql);
while($row=mysql_fetch_array($sql_sel)) //for the first query
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['stud_id'];?></td>
<td><?php echo $row['fname']." ".$row['lname'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['sub_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<td align="center"><a href="?tag=enrollment_entry&opr=upd&rs_id=<?php echo $row['enroll_num'];?>" title="Update"><img src="picture/update.png" /></a></td>
<td align="center"><a href="?tag=view_enrollments&opr=del&rs_id=<?php echo $row['enroll_num'];?>" title="Delete"><img src="picture/delete.png" /></a></td>
</tr>
<?php
}
?>
select에 enroll_num 열을 추가했으며이를 위해 두 개의 쿼리가 필요하지 않습니다. 적절한 조인이있는 하나의 쿼리는 괜찮습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다