データベースの設定
ソースコード
index.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'php_dev');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if($conn->connect_error){
die('Connection Failed ' . $conn->connect_error);
}
echo 'CONNECTED!';
$sql= 'SELECT * FROM feedback';
$result = mysqli_query($conn, $sql);
$feedback= mysqli_fetch_all($result, MYSQLI_ASSOC);
echo var_dump($feedback);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Past Feedback</h1>
<?php if(empty($feedback)): ?>
<p>There is no feedback</p>
<?php endif; ?>
<?php foreach($feedback as $item): ?>
<div>
<div>
<?php echo $item['body']; ?>
</div>
<div>
<?php echo $item['name']; ?> on <?php echo $item['date']; ?>
</div>
</div>
<?php endforeach; ?>
</body>
</html>