|
Show data records in table rows
|
|
|
|
|
Friday, 20 March 2009
|
|
HTML clipboard
There are simply to show data records in table rows, just one record by one
table row but sometime you need to show data records more than one record in one
row. This tutorial show you how can to show your data records in the table with
three columns and make multi-rows automatically with while loop.
This tutorial require 1 PHP file and 1 table of mySQL database.
- show_multi_columns.php
- Database "tutorial" and table "name_list" with 2 fields: id(auto_increment),
name(varchar, 50) and put some records about 20 - 30 records into this table.
(directly by phpMyAdmin)
Show_multi_columns.php
Source Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
mysql_connect("localhost","","");
mysql_select_db("tutorial");
$result=mysql_query("select * from name_list order by id asc");
?>
<table border="1">
<?
while($row=mysql_fetch_assoc($result)){
?>
<tr>
<td>
<? echo $row['name']; ?>
<? $row=mysql_fetch_assoc($result); ?>
</td
<td>
<? echo $row['name']; ?>
<? $row=mysql_fetch_assoc($result); ?>
</td>
<td>
<? echo $row['name']; ?>
<? $row=mysql_fetch_assoc($result); ?>
</td>
</tr>
<?
}
?>
</table>
</body>
</html>
|