Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- DROP TABLE IF EXISTS `tbl_test`;
- CREATE TABLE IF NOT EXISTS `tbl_test` (
- `id` TINYINT(3) unsigned NOT NULL AUTO_INCREMENT,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
- INSERT INTO tbl_test
- VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
- */
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='test';
- $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
- $sql="SELECT id FROM tbl_test";
- $data=array();
- if($result=$db->query($sql))
- {
- while($record=$result->fetch_object())
- {
- $data[]=$record->id;
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Test table</title>
- </head>
- <body>
- <table border='1'>
- <tr>
- <?php
- $column=7;
- $i=0;
- foreach($data as $dt)
- {
- echo ($i++%$column==0?"</tr>\n<tr>":"")."<td>$dt</td>";
- }
- for($j=0;$j<$column-($i%$column);++$j)
- {
- echo "<td> </td>";
- }
- ?>
- </tr>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement