ຊຶ່ງຈະມີຂັ້ນຕອນງ່າຍໆ ມາລອງເຮັດກັນເລີຍ
=======================================
rand.php
=======================================
<?php
// connect oop mysqli
$localhost = "localhost"; //localhost server ຈຳລອງຜ່ານ web server Xampp,Appserv
$root = "root"; // root ຂອງການຕິດຕັ້ງ ໃນ web server
$pass = "44@44"; // ລະຫັດຜ່ານທີ່ຕິດຕັ້ງໄວ້ ໃນ web server
$db = "mydatabase"; // database ທີ່ຕ້ອງການຈະຕິດຕໍ່
$con= new mysqli($localhost,$root,$pass,$db); // connection
mysqli_query($con,"set names utf8"); // set ພາສາ ເພື່ອອ່ານພາສາລາວ ໄທ ອື່ນໆ
// check connection or die
// ເມື່ອ Error ຈະຂຶ້ນສະແດງ ຂໍ້ຄວາມຕ່າງໆ ແຕ່ຖ້າຫາກ Connection ສຳເລັດ ສະບໍ່ມີຂໍ້ຄວາມຫຍັງຂຶ້ນ
if($con->connect_errno){
echo $con->connect_error;
exit;
}
?>
<html>
<head>
<meta charset="utf-8">
<title>Customer</title>
</head>
<body>
<center>
<br/>
<h3> TEST SELECT TABLE Random With OOP </h3>
<br/>
<form name="FrmRandom" id="FrmRandom" method="post">
<?php
if(isset($_POST["Random"])){
$strSQL = " SELECT * FROM user order by RAND() LIMIT 5 ";
$objQuery = $con->query($strSQL);
}
?>
<input type="submit" name="Random" id="Random" value="Random" style="width: 100px; height: 40px ; color: green; margin: 5px 10px 5px 10px; font-size:18px; " >
<table border="1" width="900" cellpadding='0' cellspacing='0'>
<tr>
<th width="61">ID</th>
<th width="207">Name</th>
<th width="100">Email</th>
</tr>
<?php
while($value = $objQuery->fetch_array()) {
?>
<tr>
<td align='center'><?php echo $value["UserID"];?></a></td>
<td align='center'><?php echo $value["UserName"];?></td>
<td align='center'><?php echo $value["Email"];?></td>
</tr>
<?php } ?>
</table>
</form>
<br/>
<h3> TEST SELECT Normal TABLE With OOP </h3>
<br/>
<?php
$strSQL = " SELECT * FROM user ORDER BY UserID ASC";
$objQuery = $con->query($strSQL);
?>
<table border="1" width="900" cellpadding='0' cellspacing='0'>
<tr>
<th width="61">ID</th>
<th width="207">Name</th>
<th width="100">Email</th>
</tr>
<?php
while($value = $objQuery->fetch_array()) {
?>
<tr>
<td align='center'><?php echo $value["UserID"];?></a></td>
<td align='center'><?php echo $value["UserName"];?></td>
<td align='center'><?php echo $value["Email"];?></td>
</tr>
<?php } ?>
</table>
</body>
<?php $con->close(); ?>
</html>
=======================================
Out Put Rand And Normal Select |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น