【发布时间】:2018-05-28 07:04:44
【问题描述】:
我创建了带有动态循环的表(如果我有 100 条记录,它应该在一张表中只显示 15 条记录)
有了这个,我有 20 条记录,创建了两个表,但问题在于列动态没有得到,并且正在显示相同的记录,用于在一个表中显示 15 条记录和在另一个表中显示 5 条记录:
这是我的代码:
<?php
$total = $totalQues / 15;
for ($row = 0; $row < $total; $row++)
{
echo '<table aria-describedby="example2_info" id="example2" class="table table-bordered table-hover dataTable custom-table pull-left col-xs-offset-1 col-lg-offset-2 col-sm-offset-2 col-md-offset-2">';
echo '<tbody aria-relevant="all" aria-live="polite" role="alert">';
echo '<tr class="odd black">';
echo '<td class=" text-center">Q</td>';
echo '<td class="text-center">C</td>';
echo '<td class="text-center">U</td>';
echo '</tr>';
$j = 0;
$k = 0;
$l = 0;
for ($i = 0; $i < 15; $i++)
{
$j = $i + $totalQues;
$k = $i + 30;
$l = $i + 45;
$m = $i + 1;
$n = $k + 1;
$o = $l + 1;
if (empty($r[1][$i]->corr_ans))
{
echo '<tr style = "color:green;">
<td>' . $m . '</td>
<td></td>
<td></td>
</tr>';
}
else
{
$uans = strtolower($r[1][$i]->corr_ans);
$cans = strtolower($r[1][$i]->user_ans);
$u = ord($uans);
$cr = ord($cans);
// echo "u=".$u."cr=".$cr;
if ($u == $cr):
echo '<tr style = "color:green;">
<td>' . $m . '</td>
<td>' . strtoupper($r[1][$i]->corr_ans) . '</td>
<td>' . strtoupper($r[1][$i]->user_ans) . '</td>
</tr>';
else:
echo '<tr style = "color:red;">
<td>' . $m . '</td>
<td>' . strtoupper($r[1][$i]->corr_ans) . '</td>
<td>' . strtoupper($r[1][$i]->user_ans) . '</td>
</tr>';
endif;
}
}
echo '</tbody>';
echo '</table>';
}
?>
【问题讨论】:
-
任何人请帮我解决这个问题
-
您想要
$total的表数或行数吗?我真的无法理解。 -
由于您的代码无法正常工作,因此我们使用您的代码来确定您正在尝试做什么并不是一个好主意。也许你可以用通俗易懂的英语解释你想要做什么。就像函数接受参数 a 和 b,a 是 ... b 是 ... 它会返回 ... 取决于 ...
-
表格数量。但在一个 for 循环中创建相同的记录 @seethrough 你可以参考我的图片我 atteched
-
@HMR 我有 20 条记录作为 totalQues,我必须创建一个限制为 15 列的表,其余 5 列必须显示另一个表