การเขียนโปรแกรม PHP กับ MySQL เพื่อดึงข้อมูลจาก Table มาแสดง
<?php
$objConnect = mysql_connect("localhost","root","1234") or die(mysql_error());
$objDB = mysql_select_db("test");
mysql_query("SET NAMES UTF8");
?>
<html> <head>
<title>PHP & MySQL Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body>
<?php
$strSQL = "SELECT * FROM product";
$objQuery = mysql_query($strSQL) or die (mysql_error()); ?> <table width="1000" border="1"> <tr>
<th width="91"> <div align="center">CustomerID </div></th> <th width="98"> <div align="center">Name </div></th>
<th width="97"> <div align="center">CountryCode </div></th> <th width="198"> <div align="center">Email </div></th>
</tr> <th width="59"> <div align="center">Budget </div></th> <th width="71"> <div align="center">Used </div></th>
<td><div align="center"><?php echo $objResult["CustomerID"];?></div></td> <?php while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><?php echo $objResult["Name"];?></td>
<td><div align="center"><?php echo $objResult["CountryCode"];?></div></td> <td><?php echo $objResult["Email"];?></td> <td align="right"><?php echo $objResult["Budget"];?></td>
</html> <td align="right"><?php echo $objResult["Used"];?></td> </tr> <?php } ?> </table>
</body>
$objConnect = mysql_connect("localhost","root","1234") or die(mysql_error());
$objDB = mysql_select_db("test");
mysql_query("SET NAMES UTF8");
?>
<html> <head>
<title>PHP & MySQL Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body>
<?php
$strSQL = "SELECT * FROM product";
$objQuery = mysql_query($strSQL) or die (mysql_error()); ?> <table width="1000" border="1"> <tr>
<th width="91"> <div align="center">CustomerID </div></th> <th width="98"> <div align="center">Name </div></th>
<th width="97"> <div align="center">CountryCode </div></th> <th width="198"> <div align="center">Email </div></th>
</tr> <th width="59"> <div align="center">Budget </div></th> <th width="71"> <div align="center">Used </div></th>
<td><div align="center"><?php echo $objResult["CustomerID"];?></div></td> <?php while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><?php echo $objResult["Name"];?></td>
<td><div align="center"><?php echo $objResult["CountryCode"];?></div></td> <td><?php echo $objResult["Email"];?></td> <td align="right"><?php echo $objResult["Budget"];?></td>
</html> <td align="right"><?php echo $objResult["Used"];?></td> </tr> <?php } ?> </table>
</body>
ความคิดเห็น
แสดงความคิดเห็น