php - How to show data in multiple html table a database query result -


hello trying solve problem. i've research , take time unable solve sorry that.

i trying show database table query result in multiple table on html page , every table should range i've put here 5 row @ table if query contain 29 row show on 6 table , last table contain 4 result serial no of table correctly if first table 1st row 01 2nd table 1st row 06. "the query result not constant depend on database record"

here code shows 1 table not showing others table result.

thanks time. :)

$students = db::table('mark_prc')             ->select('student_roll','mark')             ->where('cen_code', $c_code)             ->where('sub_code',$subject)             ->get();      $k=0; //counter serial no     $m=5; // no of row each table     $c = count($students); // have data on array after query 29     $p = ceil($c/5); // data should show on 6 tables      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>';     } 

not sure why, for($j=$k;is doing reference assignment, $j=&$k.

a workaround -

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

the ($i*$m), gets start value, , ($i*$m)+$m) adds 'no of row each table' min((($i*$m)+$m),$c) in $j<min((($i*$m)+$m),$c) max out loop @ $c.

so code -

$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); // have data on array after query 29     $p = ceil($c/5); // data should show on 6 tables      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>';     } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -