File: /var/www/net/vpnaddresstomysql.php
<?php
include "name.php";
include "mysqllink.php";
$id = $_POST['id'];
$address = $_POST['address'];
$fblink = "select * from $tbname " ;
$freslut = $dblink->query($fblink ) ;
if ($freslut) {
$md=0;
while ($nb = mysqli_fetch_array ($freslut)){
$ros[$md]["name"]=$nb["name"];
$ros[$md]["address"]=$nb["address"];
$md++;
}
}
$itemsPerPage = 16;
$totalItems = $md;
$totalPages = ceil($totalItems / $itemsPerPage);
$currentPage = isset($_GET['page']) ? intval($_GET['page']) : 1;
$offset = ($currentPage - 1) * $itemsPerPage;
// 取得當前頁面的資料
usort($ros, function($a, $b) {
return $a['name'] - $b['name'];
});
// 使用 array_slice 获取当前页面的数据
$currentPageData = array_slice($ros, $offset, $itemsPerPage);
?>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>社區列表</title>
<style>
form {
display: inline-block;
margin-right: 10px; /* 設定按鈕之間的間距 */
}
</style>
</head>
<h3>社區列表</h3>
<form action="vpnnew.php" method="post">
<input type="submit" value="編輯" >
</form>
<form action="index.html" method="post">
<input type="submit" value="回流量圖" >
</form>
<body align="center">
<table border="1" cellspacing="0" cellpadding="4" bordercolorlight="#3333FF" bordercolordark="#FFFFFF" align="center">
<tr>
<td>
社區編號
</td>
<td>
vpn address
</td>
</tr>
<?php
foreach ($currentPageData as $row) {
echo "<tr>";
echo "<td>".$row['name']."</td>" ;
echo "<td>".$row['address']."</td>" ;
echo "</tr>";
}
?>
</table>
<div style="text-align: center; margin-top: 10px;">
<?php
// 顯示上下頁按鈕
if ($currentPage > 1) {
echo '<a href="?page='.($currentPage - 1).'">上一頁</a>';
}
// 下拉式選單代替頁數連結
echo '<select id="page" name="page" onchange="navigateToPage(this.value)">';
for ($i = 1; $i <= $totalPages; $i++) {
echo '<option value="'.$i.'" '.($i == $currentPage ? 'selected' : '').'>'.$i.'</option>';
}
echo '</select>';
if ($currentPage < $totalPages) {
echo '<a href="?page='.($currentPage + 1).'">下一頁</a>';
}
?>
<script>
// JavaScript 函式用於手動導向到選擇的頁面
function navigateToPage(selectedPage) {
window.location.href = '?page=' + selectedPage;
}
</script>
</div>
</body>
</html>