db_mysqli
修改功能-以下為列表list_all.php

db_mysqli
list_all.php
<?php
include 'config.php';
// 連接資料庫
$link = db_open();
$sqlstr = "SELECT * FROM person ";
$result = mysqli_query($link, $sqlstr);
$total_rec = mysqli_num_rows($result);
$data = '';
while($row=mysqli_fetch_array($result, MYSQLI_ASSOC))
{
db_mysqli
$uid = $row['uid'];
$usercode = $row['usercode'];
$username = $row['username'];
$address = $row['address'];
$birthday = $row['birthday'];
$height = $row['height'];
$weight = $row['weight'];
$remark = $row['remark'];
// 依需要調整顯示內容
$str_birthday = date('Y-m-d', strtotime($birthday));
db_mysqli
$data .= <<< HEREDOC
<tr>
<td>{$uid}</td>
<td>{$usercode}</td>
<td>{$username}</td>
<td>{$address}</td>
<td>{$str_birthday}</td>
<td>{$height}</td>
<td>{$weight}</td>
<td>{$remark}</td>
<td><a href="display.php?uid={$uid}">詳細</a></td>
<td><a href="edit.php?uid={$uid}">修改</a></td>
db_mysqli
<td><a href="delete.php?uid={$uid}" onclick="return confirm('確定要刪除嗎?');">刪除</a></td>
</tr>
HEREDOC;
}
db_close($link);
db_mysqli
$html = <<< HEREDOC
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>基本資料庫系統</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<p><a href="index.php">回首頁</a></p>
<h2 align="center" align="center">共有 {$total_rec} 筆記錄</h2>
<table border="1" align="center">
以下為view
db_mysqli
<tr>
<th>序號</th>
<th>代碼</th>
<th>姓名</th>
<th>地址</th>
<th>生日</th>
<th>身高</th>
<th>體重</th>
<th>備註</th>
<td colspan="3" align="center">操作 [<a href="add.php">新增記錄</a>]</td>
</tr>
{$data}
</table>
db_mysqli
</body>
</html>
HEREDOC;
echo $html;
?>
db_mysqli
<?php
include 'config.php';
$uid = isset($_GET['uid']) ? $_GET['uid'] : 0;
// 連接資料庫
$link = db_open();
$sqlstr = "SELECT * FROM person WHERE uid=" . $uid;
$result = mysqli_query($link, $sqlstr);
if($row=mysqli_fetch_array($result))
{
edit.php
db_mysqli
$uid = $row['uid'];
$usercode = $row['usercode'];
$username = $row['username'];
$address = $row['address'];
$birthday = $row['birthday'];
$height = $row['height'];
$weight = $row['weight'];
$remark = $row['remark'];
db_mysqli
$data = <<< HEREDOC
<form action="edit_save.php" method="post">
<p>代碼:<input type="text" name="usercode" value="{$usercode}"></p>
<p>姓名:<input type="text" name="username" value="{$username}"></p>
<p>地址:<input type="text" name="address" value="{$address}"></p>
<p>生日:<input type="text" name="birthday" value="{$birthday}"></p>
<p>身高:<input type="text" name="height" value="{$height}"></p>
<p>體重:<input type="text" name="weight" value="{$weight}"></p>
<p>備註:<input type="text" name="remark" value="{$remark}"></p>
<input type="hidden" name="uid" value="{$uid}">
<input type="submit" value="送出">
</form>
db_mysqli
HEREDOC;
}
else
{
$data = '找不到資料';
}
db_close($link);
$html = <<< HEREDOC
<!DOCTYPE html>
<html>
<head>
db_mysqli
<meta charset="UTF-8">
<title>基本資料庫系統</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<p><a href="index.php">回首頁</a></p>
<h2 align="center">修改資料</h2>
{$data}
</body>
</html>
HEREDOC;
echo $html;
?>