Advertisement
cdsatrian

table test

Oct 7th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2. /*
  3. DROP TABLE IF EXISTS `tbl_test`;
  4. CREATE TABLE IF NOT EXISTS `tbl_test` (
  5.   `id` TINYINT(3) unsigned NOT NULL AUTO_INCREMENT,
  6.   PRIMARY KEY (`id`)
  7. ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
  8.  
  9. INSERT INTO tbl_test
  10. VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
  11. */
  12. $dbhost='localhost';
  13. $dbuser='root';
  14. $dbpass='';
  15. $dbname='test';
  16. $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
  17. $sql="SELECT id FROM tbl_test";
  18. $data=array();
  19. if($result=$db->query($sql))
  20. {
  21.   while($record=$result->fetch_object())
  22.   {
  23.     $data[]=$record->id;
  24.   }
  25. }
  26. ?>
  27. <!DOCTYPE html>
  28. <html>
  29.   <head>
  30.     <title>Test table</title>
  31.   </head>
  32.   <body>
  33.     <table border='1'>
  34.       <tr>
  35.       <?php
  36.       $column=7;
  37.       $i=0;
  38.       foreach($data as $dt)
  39.       {
  40.         echo ($i++%$column==0?"</tr>\n<tr>":"")."<td>$dt</td>";
  41.       }
  42.       for($j=0;$j<$column-($i%$column);++$j)
  43.       {
  44.         echo "<td>&nbsp;</td>";
  45.       }
  46.       ?>
  47.       </tr>
  48.     </table>
  49.   </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement