繁体   English   中英

如何在多个html表中显示数据的数据库查询结果

[英]How to show data in multiple html table a database query result

您好,我正在尝试解决问题。 我已经研究并花了一些时间,但对此无法解决,对不起。

我正在尝试在html页上的多个表中显示数据库表查询结果,并且每个表都应在一个表中放置5行的范围内,因此如果我的查询包含29行,那么它将在6个表中显示,最后一个表将包含4个结果,如果第一个表的第1行为01,然后第2个表的第1行为06,则表的序列号正确。“查询结果不是恒定的,但将取决于数据库记录”

这是我的代码,它仅显示1个表,但不显示其他结果表。

谢谢你的时间。 :)

$students = DB::table('mark_prc')
            ->select('student_roll','mark')
            ->where('cen_code', $c_code)
            ->where('sub_code',$subject)
            ->get();

    $k=0; //counter for serial no
    $m=5; // no of row each table
    $c = count($students); // now have data on array after query 29
    $p = ceil($c/5); // the data should be show on 6 tables now

    for($i=0;$i<$p;$i++){
   echo "<table>
            <tr>
                <th>SL</th>
                <th>Roll</th>
                <th>Mark</th>
            </tr>";
        for($j=$k;$j<$m;$j++){
            echo '<tr>
                    <td>'.($k+1).'</td>
                    <td>'.$students[$k]->student_roll.'</td>
                    <td>'.$students[$k]->mark.'</td>
                  <tr>';
            $k++;
        }
        echo '</table>';
    }

不知道为什么,但是for($j=$k;正在执行引用分配,因此$j=&$k

一种解决方法是-

for($j=($i*$m);$j<min((($i*$m)+$m),$c);$j++){

($i*$m) ,获取您的起始值,而($i*$m)+$m)添加“每个表的行数” min((($i*$m)+$m),$c)$j<min((($i*$m)+$m),$c)是到最大出在环路$c

因此,您的代码现在看起来像-

$students = DB::table('mark_prc')
            ->select('student_roll','mark')
            ->where('cen_code', $c_code)
            ->where('sub_code',$subject)
            ->get();

    $m=5; // no of row each table
    $c = count($students); // now have data on array after query 29
    $p = ceil($c/5); // the data should be show on 6 tables now

    for($i=0;$i<$p;$i++){
   echo "<table>
            <tr>
                <th>SL</th>
                <th>Roll</th>
                <th>Mark</th>
            </tr>";
        for($j=(($i*$m));$j<min((($i*$m)+$m),$c);$j++){
            echo '<tr>
                    <td>'.($j+1).'</td>
                    <td>'.$students[$j]->student_roll.'</td>
                    <td>'.$students[$j]->mark.'</td>
                  <tr>';
        }
        echo '</table>';
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM