我需要你帮助我的脚本。。我试图将查询的一些内容回显到html表中,但我想在每7个参数处中断它。下面的脚本只分解了前七个,而其余的没有间隔分解,它们也从html表中得到了响应。
我该怎么做。感谢您的时间和帮助。
echo "<table class='"altrowstable'" bgcolor = gold >'n";
$count = 0;
echo "<tr align= '"center'">'n";
$carry_over = array();
$score_count = mysql_numrows($query8);
echo "<td>" . "Failed: ";
if ($score_count !== 0) {
while ($row8 = mysql_fetch_assoc($query8)) {
echo "<th>" . $row8['course_code'] . "</th>";
if ($count == 7) {
echo "</tr>'n";
echo "</table>";
}
}
}
使用模运算符而不是相等
if ( ($count+1) % 7 ){
+1在那里,所以它不会在$count == 0
上立即中断,因为0%n
是0
您需要使用模运算符%
,它返回除法后的余数。$count % 7 ==0
表示当前计数是7的倍数,您应该中断。您还需要递增$count
。
echo "<table class='"altrowstable'" bgcolor = gold >'n";
$count = 0;
echo "<tr align= '"center'">'n";
$carry_over = array();
$score_count = mysql_numrows($query8);
echo "<td>"."Failed: ";
if($score_count !== 0){
while ($row8 = mysql_fetch_assoc($query8)) {
echo "<th>".$row8['course_code']."</th>";
// Increment $coutn
$count++;
// Check the modulus
if ( $count % 7 == 0 ){
echo "</tr>'n";
echo "</table>";
}
}
}