Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //-- jumlah data yang akan ditampilkan, random dari 3 sd 26
- $num_data=rand(3,26);
- //-- jumlah baris maksimum = 5
- $max_row=5;
- $data=array();
- for($no=1;$no<=$num_data;++$no){
- $data[$no]="data ke-{$no}";
- }
- $row_col_data=array();
- $row=1;
- $col=1;
- foreach($data as $no=>$dt){
- if(!isset($row_col_data[$row]))
- $row_col_data[$row]=array();
- $row_col_data[$row][$col]=$dt;
- if($row % $max_row == 0) {
- ++$col;
- $row=1;
- } else {
- ++$row;
- }
- }
- ?>
- Jumlah data : <?php echo $num_data;?><br>
- Jumlah baris : <?php echo $max_row;?><br>
- <table border="1">
- <tr>
- <?php
- $col=$row==1?--$col:$col;
- for($ncol=1;$ncol<=$col;++$ncol){
- echo "<th>kolom ke-{$ncol}</th>";
- }
- ?>
- </tr>
- <?php
- for($nrow=1;$nrow<=$max_row;++$nrow){
- echo "<tr>";
- for($ncol=1;$ncol<=$col;++$ncol){
- echo "<td>".(isset($row_col_data[$nrow][$ncol])?$row_col_data[$nrow][$ncol]:' ')."</td>";
- }
- echo "</tr>";
- }
- ?>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement