คำสั่งในการแสดงข้อมูลจากฐานข้อมูล
CREATE TABLE `student` (
`id` varchar(5) NOT NULL,
`password` varchar(20) NOT NULL,
`title` varchar(10) NOT NULL,
`name` varchar(50) NOT NULL,
`surname` varchar(50) NOT NULL,
`birthdate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='เก็บข้อมูลนักเรียน';
--
-- dump ตาราง `student`
--
INSERT INTO `student` VALUES ('11111', '111', 'นาย', 'สุธน', 'ภักดี', '2015-08-19');
/*-----------------------------------------------------------------------------------------------------*/
<?php
$link = mysql_pconnect("localhost","root","12345") or die(mysql_error());
mysql_select_db("",$link) or die(mysql_error());
mysql_query("SET NAMES UTF8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>
<?php
$sql="select * from order by id asc";
$result=mysql_query($sql1) or die(mysql_error());
$num=mysql_num_rows($result);
echo "จำนวนทั้งหมด ".$num." คน<br>";
?>
<table width="554" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="51"><div align="center">ลำดับ</div></td>
<td width="89"><div align="center">รหัส</div></td>
<td width="170"><div align="center">ชื่อ</div></td>
</tr>
<?php
$i=0;
while($rs=mysql_fetch_array($result)){
$i++;
extract($rs);
?>
<tr>
<td><div align="center"><?php echo $i; ?></div></td>
<td><div align="left"><?php echo $id; ?> </div></td>
<td><div align="left"><?php echo $name; ?> </div></td>
</tr><?php }?>
</table>
</body>
</html>
<?php
$link = mysql_pconnect("localhost","root","12345") or die(mysql_error());
mysql_select_db("",$link) or die(mysql_error());
mysql_query("SET NAMES UTF8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>
<?php
$sql="select * from order by id asc";
$result=mysql_query($sql1) or die(mysql_error());
$num=mysql_num_rows($result);
echo "จำนวนทั้งหมด ".$num." คน<br>";
?>
<table width="554" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="51"><div align="center">ลำดับ</div></td>
<td width="89"><div align="center">รหัส</div></td>
<td width="170"><div align="center">ชื่อ</div></td>
</tr>
<?php
$i=0;
while($rs=mysql_fetch_array($result)){
$i++;
extract($rs);
?>
<tr>
<td><div align="center"><?php echo $i; ?></div></td>
<td><div align="left"><?php echo $id; ?> </div></td>
<td><div align="left"><?php echo $name; ?> </div></td>
</tr><?php }?>
</table>
</body>
</html>
ความคิดเห็น
แสดงความคิดเห็น