วันจันทร์ที่ 24 ธันวาคม พ.ศ. 2561

SELECT TABLE FROM DATABASES ON PHP BY OOP

ຈາກບົດຄວາມທີ່ 2 ທີ່ໄດ້ຂຽນໄປໃນການຕິດຕໍ່ກັບ ຖານຂໍ້ມູນ ມາໃນບົດຄວາມນີ້ ສິໄດ້ສອນກ່ຽວກັບການ ສະແດງຂໍ້ມູນອອກມາ ຈາກ Table ໂດຍ ໃຊ້ຊຸດຄຳສັ່ງ Mysql SELECT * FROM ... ແລະ ທຳການ ສະແດງຂໍ້ມູນຜ່ານ ການ Loop While Fetch_array ຊຶ່ງຈະມີຂັ້ນຕອນທີ່ແສນຈະງ່າຍ ສາມາດເຮັດຕາມໄດ້ ດັ່ງ Code ຕໍ່ໄປນີ້

<?php
// connect oop mysqli
$localhost = "localhost"; //localhost server ຈຳລອງຜ່ານ web server Xampp,Appserv
$root = "root"; // root ຂອງການຕິດຕັ້ງ ໃນ web server
$pass = "xxx"; // ລະຫັດຜ່ານທີ່ຕິດຕັ້ງໄວ້ ໃນ web server
$db = "db_test"; // 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;
}
// end to connection statement
?>

<?php
$strSQL = " SELECT * FROM customer ";
$objQuery = $con->query($strSQL);
?>
<html>
<head>
<meta charset="utf-8">
<title>Customer</title>
</head>
<body>
<center>
<br/>
<h3> TEST SELECT TABLE  customer  With OOP </h3>
<br/>
<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>
        <th width="100">CountryCode</th>
<th width="129">Used</th>
<th width="103">Bath</th>

</tr>
<?php
while($value = $objQuery->fetch_array()) {
?>
<tr>
<td align='center'><?php echo  $value["CustomerID"];?></td>
<td align='center'><?php echo  $value["Name"];?></td>
<td align='center'><?php echo  $value["Email"];?></td>
<td align='center'><?php echo  $value["CountryCode"];?></td>
<td align='center'><?php echo  $value["Used"];?></td>
<td align='center'><?php echo  $value["bath"];?></td>
</tr>
<?php } ?>
<?php $con->close(); ?>

</table>
</body>
</html>

ເຮົາມາເບິ່ງ Out Put ທີ່ໄດ້
Result on OOP















ຂໍ້ມູນດິບ ຈາກຖານຂໍ້ມູນ ທີ່ບໍ່ທັນຜ່ານການຂຽນດ້ວຍ PHP















ບົດຄວາມນີ້ກະຈົບໄປ ຫວັງວ່າສິມີປະໂຫຍດນຳຜູ້ທີ່ ສຶກສາ ທາງດ້ານການຂຽນ ການຮຽນ ພາສາ PHP
ພົບກັນໃໝ່ໃນບົດຄວາມໜ້າ
ຢ່າລືມກົດຕິດຕາມ ໃຫ້ກຳລັງໃຈແນ່ເດິ້
ໂປຣແກຣມເມີ ທຳມະດາຄົນໜຶ່ງ ທີ່ມັກຕຶກປາ ແລະ ຮ້ອງເພລງ By Mr. HaraRock

ไม่มีความคิดเห็น:

แสดงความคิดเห็น