<file connect.php----------------->
<?php
// CONNECT TO THE DATABASE
$hostname_conn_Mysqli = 'localhost';
$username_conn_Mysqli = 'root';
$password_conn_Mysqli = 'xxxxx';
$database_conn_Mysqli = 'xxxxx';
$mysqli = new mysqli($hostname_conn_Mysqli, $username_conn_Mysqli, $password_conn_Mysqli, $database_conn_Mysqli);
mysqli_set_charset($mysqli,"utf8");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
function return_rows($db,$query) {
$res = $db->query($query) or die($db->error.__LINE__);
if($res->num_rows > 0) {
return $res;
}
}
?>
<ใน Dreamweaver------------------>
<?php require_once('Connections/conn_Mysqli.php'); ?>
<?php
$com = "SELECT * FROM xxxx";
$rs_mysqli = return_rows($mysqli,$com);
?>
<!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>Mysqli data show</title>
</head>
<body>
<?php
if($rs_mysqli->num_rows > 0) { ?> //ตรวจสอบข้อมูลว่ามากกว่า 0
<table border="1" align="center">
<tr>
<td><div align="center"><strong>r_date</strong></div></td>
<td><div align="center"><strong>fore24</strong></div></td>
<td><div align="center"><strong>tail24</strong></div></td>
</tr>
<?php
while($row_rs_mysqli = $rs_mysqli->fetch_assoc()) { ?> //วน Loop ดึงข้อมูลมาแสดง
<tr>
<td><?php echo $row_rs_mysqli['r_date']; ?></td>
<td><?php echo $row_rs_mysqli['fore24']; ?></td>
<td><?php echo $row_rs_mysqli['tail24']; ?></td>
</tr>
<?php }
$totalRows_rs_mysqli = mysqli_num_rows($rs_mysqli); //นับจำนวน Record ทั้งหมด
} else {
echo "<h1><center>file not found </center></h1>";
}
echo $totalRows_rs_mysqli; //แสดงจำนวน Record
?>
</table>
</body>
</html>
<?php
mysqli_close($mysqli); //ปิด Connection
?>