PHP 將資料庫資料橫向排入表格內
使用語法:PHP、SQL、HTML
範例說明:將資料庫的資料取出來之後,放入指定的欄數裡面,通常抓取的資料會以縱向向下排列,
此範例使用簡單的寫法讓資料乖乖橫向排列。
Test.php
	<?php  require_once('bsm/Connections/test.php');
	  mysql_select_db($database_test, $test);
	  $query_record = "SELECT name FROM recordfile";
	  $record = mysql_query($query_record, $test) or die(mysql_error());
	  $row_record = mysql_fetch_assoc($record);
	  $totalRows = mysql_num_rows($record);
	?>
	<html>
	 <head><title></title>
	    </head>
	    <body>
	     <table border="1">
	         <tr>
	      <?php $i=1;
	      do{
	        if($i%3 == 1){
	         echo '<tr><td>'.$row_record['name'].'</td>';
	        }
	        elseif ($i%3 == 2){
	         echo '<td>'.$row_record['name'].'</td>';
	        }
	         elseif ($i%3 == 0){
	        echo '<td>'.$row_record['name'].'</td></tr>';
	        }
	        $i++;
	     }while($row_record = mysql_fetch_array($record));
	     ?>
	         </tr>
	      </table>
	    </body>
	</html>
顯示結果如下圖:
參考或是複製語法時,別忘了留個言喔 ^ ^ ~
