请问<td style="cursor:pointer">标签是做什么用的?

本文详细介绍了 CSS 中的 cursor 属性及其应用场景。该属性能够改变鼠标指针在特定元素上的显示样式,例如当鼠标悬停在可点击的表格单元格上时,指针将变为手形图标。

请问<td style="cursor:pointer">标签是做什么用的?

专业回答
2015-08-23 18:11
css的一种样式,作用是当鼠标移动到该单元格上时,鼠标会由箭头形状改为手的形状。

附:cursor属性
十字准心 cursor: crosshair;
手 cursor: pointer;
cursor: hand;
写两个是为了照顾IE5,它只认hand。
等待/沙漏 cursor: wait;
帮助 cursor: help;
无法释放 cursor: no-drop;
文字/编辑 cursor: text;
可移动对象 cursor: move;
向上改变大小(North) cursor: n-resize;
向下改变大小(South) cursor: s-resize;
向右改变大小(East) cursor: e-resize;
向左改变大小(West) cursor: w-resize;
向上右改变大小(North East) cursor: ne-resize;
向上左改变大小(North West) cursor: nw-resize;
向下右改变大小(South East) cursor: se-resize;
向下左改变大小(South West) cursor: sw-resize;
自动 cursor: auto;
禁止 cursor:not-allowed;
处理中 cursor: progress;
系统默认 cursor: default;
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>动态编辑 t_accounts 数据表</title> <style> body { font-family: Arial, sans-serif; margin: 20px; background-color: #f7f7f7; } table { width: 100%; border-collapse: collapse; margin-top: 20px; background-color: #fff; } th, td { border: 1px solid #ccc; padding: 10px; text-align: left; } th { background-color: #007BFF; color: white; } input[type="text"], input[type="password"] { width: 100%; padding: 5px; box-sizing: border-box; } button.save { background-color: #28a745; color: white; border: none; padding: 5px 10px; cursor: pointer; } .pagination { margin: 20px 0; text-align: center; } .pagination a, .pagination span { display: inline-block; margin: 0 3px; padding: 8px 12px; text-decoration: none; border: 1px solid #ccc; background-color: #fff; color: #007BFF; } .pagination a:hover { background-color: #007BFF; color: white; } .pagination .current { background-color: #007BFF; color: white; font-weight: bold; } .pagination .ellipsis { color: #999; background-color: transparent; border: none; } </style> </head> <body> <h1>MySQL 数据表:t_accounts(自动识别主键)</h1> <p>本页面自动识别主键字段,支持安全更新。</p> <table> <thead> <tr> <th>Uid</th> <th>Name</th> <th>Email</th> <th>Type</th> <th>玩家昵称</th> <th>操作</th> </tr> </thead> <tbody> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="11"> <td> 11 <input type="hidden" name="uid" value="11"> </td> <td> <input type="text" name="name" value="B0A539C5" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="12"> <td> 12 <input type="hidden" name="uid" value="12"> </td> <td> <input type="text" name="name" value="A45FE7FA" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="13"> <td> 13 <input type="hidden" name="uid" value="13"> </td> <td> <input type="text" name="name" value="BB7D2BDD" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="14"> <td> 14 <input type="hidden" name="uid" value="14"> </td> <td> <input type="text" name="name" value="A6B0C80F" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="15"> <td> 15 <input type="hidden" name="uid" value="15"> </td> <td> <input type="text" name="name" value="3DDF7141" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="16"> <td> 16 <input type="hidden" name="uid" value="16"> </td> <td> <input type="text" name="name" value="4C17A206" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="17"> <td> 17 <input type="hidden" name="uid" value="17"> </td> <td> <input type="text" name="name" value="A781F182" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="18"> <td> 18 <input type="hidden" name="uid" value="18"> </td> <td> <input type="text" name="name" value="15391F13" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="19"> <td> 19 <input type="hidden" name="uid" value="19"> </td> <td> <input type="text" name="name" value="17CE0F27" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <input type="hidden" name="uid" value="20"> <td> 20 <input type="hidden" name="uid" value="20"> </td> <td> <input type="text" name="name" value="A8D2363B" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="email" value="syxywl.cn@qq.com" style="width:100%; padding:5px;"> </td> <td> <input type="text" name="type" value="1" style="width:100%; padding:5px;"> </td> <!-- 显示从 db_hk4e_user_gio.t_player_uid 查到的 name --> <td> <i style="color:#999;">未找到</i> </td> <!-- 隐藏其他字段防止丢失 --> <input type="hidden" name="mobile" value="12345678910"> <input type="hidden" name="password" value="syxywlcn"> <input type="hidden" name="epoch_created" value="1757223346"> <td><button type="submit" class="save">保存</button></td> </form> </tr> </tbody> </table> <!-- 调试:显示 db_hk4e_user_gio.t_player_uid 的前 10 条数据 --> <div style="margin-top:50px; border:1px solid #ccc; padding:20px; background:#f9f9f9;"> <h3>🔍 调试信息:db_hk4e_user_gio.t_player_uid 表前 10 条记录</h3> <table border='1' cellpadding='8' cellspacing='0' style='border-collapse:collapse; width:100%;'><thead><tr><th style='text-align:left; background:#eee;'>uid</th><th style='text-align:left; background:#eee;'>account_type</th><th style='text-align:left; background:#eee;'>account_uid</th><th style='text-align:left; background:#eee;'>create_time</th><th style='text-align:left; background:#eee;'>ext</th><th style='text-align:left; background:#eee;'>tag</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>1</td><td>2025-03-19 01:45:28</td><td>{"reg_platform":3} </td><td>0</td></tr><tr><td>202590100</td><td>1</td><td>6</td><td>2025-09-07 19:06:24</td><td>{"reg_platform":3} </td><td>0</td></tr><tr><td>202590101</td><td>0</td><td>1</td><td>2025-09-09 23:39:53</td><td>{"reg_platform":1} </td><td>0</td></tr><tr><td>202590102</td><td>1</td><td>5</td><td>2025-09-10 21:50:04</td><td>{"reg_platform":3} </td><td>0</td></tr><tr><td>202590103</td><td>1</td><td>107</td><td>2025-09-13 21:53:01</td><td>{"reg_platform":3} </td><td>0</td></tr><tr><td>202590104</td><td>1</td><td>108</td><td>2025-09-15 22:22:06</td><td>{"reg_platform":2} </td><td>0</td></tr><tr><td>202590105</td><td>1</td><td>109</td><td>2025-09-15 22:42:28</td><td>{"reg_platform":3} </td><td>0</td></tr><tr><td>202590106</td><td>1</td><td>110</td><td>2025-09-16 04:40:10</td><td>{"reg_platform":3} </td><td>0</td></tr><tr><td>202590107</td><td>1</td><td>112</td><td>2025-09-18 18:03:13</td><td>{"reg_platform":2} </td><td>0</td></tr><tr><td>202590108</td><td>1</td><td>115</td><td>2025-09-18 19:12:09</td><td>{"reg_platform":2} </td><td>0</td></tr></tbody></table></div> <!-- 分页导航 --> <div class="pagination"> <a href="?page=1">上一页</a> <a href="?page=1">1</a> <span class="current">2</span> <a href="?page=3">3</a> <span class="ellipsis">...</span> <a href="?page=366">366</a> <a href="?page=3">下一页</a> <span style="margin-left: 20px;">共 3657 条记录,366 页</span> </div> </body> </html> 全部重写整理完毕整体发我
最新发布
10-09
<?php // 配置数据库连接 $host = 'localhost'; $dbname = 'syxywl.cn_sdk-14'; // 含特殊字符需用反引号包裹 $username = 'root'; $password = 'qq28009618'; $dsn = "mysql:host=$host;dbname=$dbname;charset=utf8mb4"; try { $pdo = new PDO($dsn, $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("数据库连接失败: " . $e->getMessage()); } // 设置分页参数 $limit = 10; $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $page = max(1, $page); $offset = ($page - 1) * $limit; // === 获取主键字段名 === function getPrimaryKey($pdo, $table) { $stmt = $pdo->prepare("DESCRIBE `$table`"); $stmt->execute(); $columns = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($columns as $col) { if ($col['Key'] === 'PRI') { return $col['Field']; // 返回主键字段名 } } return null; // 没有主键 } $primaryKey = getPrimaryKey($pdo, 't_accounts'); if (!$primaryKey) { die("错误:t_accounts 表没有定义主键!"); } // 处理封禁请求 if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['action'] === 'ban') { $pkValue = $_POST[$primaryKey]; try { $sql = "UPDATE `t_accounts` SET `type` = 99 WHERE `$primaryKey` = ?"; $stmt = $pdo->prepare($sql); $stmt->execute([$pkValue]); $successMsg = "用户 <strong>" . htmlspecialchars($pkValue) . "</strong> 已成功封禁(type=99)!"; } catch (PDOException $e) { $errorMsg = "封禁失败: " . htmlspecialchars($e->getMessage()); } } // 查询总行数 $totalStmt = $pdo->query("SELECT COUNT(*) FROM `t_accounts`"); $totalRows = $totalStmt->fetchColumn(); $totalPages = ceil($totalRows / $limit); // 获取当前页数据(仅 uid, name, type) $stmt = $pdo->prepare("SELECT `uid`, `name`, `type` FROM `t_accounts` LIMIT ? OFFSET ?"); $stmt->bindValue(1, $limit, PDO::PARAM_INT); $stmt->bindValue(2, $offset, PDO::PARAM_INT); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>封禁 t_accounts 用户</title> <style> body { font-family: Arial, sans-serif; margin: 20px; background-color: #f7f7f7; color: #333; } h1 { color: #d32f2f; } table { width: 100%; border-collapse: collapse; margin-top: 20px; background-color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.1); } th, td { border: 1px solid #ddd; padding: 10px; text-align: left; } th { background-color: #d32f2f; color: white; } .type-99 { background-color: #ffcdd2; color: #c62828; padding: 2px 6px; border-radius: 3px; font-weight: bold; } button.ban { background-color: #d32f2f; color: white; border: none; padding: 5px 10px; cursor: pointer; border-radius: 4px; font-weight: bold; } button.ban:hover { background-color: #b71c1c; } button.ban[disabled] { background-color: #ccc; cursor: not-allowed; } .pagination { margin: 20px 0; text-align: center; } .pagination a, .pagination span { display: inline-block; margin: 0 3px; padding: 8px 12px; text-decoration: none; border: 1px solid #ccc; background-color: #fff; color: #d32f2f; border-radius: 4px; } .pagination a:hover { background-color: #d32f2f; color: white; } .pagination .current { background-color: #d32f2f; color: white; font-weight: bold; } .msg { padding: 10px; margin: 10px 0; border-radius: 4px; } .msg.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .msg.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } </style> </head> <body> <h1>⚠️ 封禁系统:t_accounts 用户管理</h1> <p>点击“封禁”按钮将用户 <code>type</code> 改为 <strong>99</strong>(封禁状态)。</p> <?php if (isset($successMsg)): ?> <div class="msg success"><?= $successMsg ?></div> <?php endif; ?> <?php if (isset($errorMsg)): ?> <div class="msg error"><?= $errorMsg ?></div> <?php endif; ?> <?php if (!empty($rows)): ?> <table> <thead> <tr> <th>Uid</th> <th>Name</th> <th>Type</th> <th>操作</th> </tr> </thead> <tbody> <?php foreach ($rows as $row): ?> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="ban"> <input type="hidden" name="<?= htmlspecialchars($primaryKey) ?>" value="<?= htmlspecialchars($row['uid']) ?>"> <td><?= htmlspecialchars($row['uid']) ?></td> <td><?= htmlspecialchars($row['name']) ?></td> <td> <?php if ($row['type'] == 99): ?> <span class="type-99">已封禁</span> <?php else: ?> <?= htmlspecialchars($row['type']) ?> <?php endif; ?> </td> <td> <?php if ($row['type'] == 99): ?> <button type="button" class="ban" disabled>已封禁</button> <?php else: ?> <button type="submit" class="ban" onclick="return confirm('确定要封禁用户 UID=<?= $row['uid'] ?> 吗?')">封禁</button> <?php endif; ?> </td> </form> </tr> <?php endforeach; ?> </tbody> </table> <!-- 分页导航 --> <div class="pagination"> <?php if ($page > 1): ?> <a href="?page=<?= $page - 1 ?>">上一页</a> <?php else: ?> <span>上一页</span> <?php endif; ?> <?php $maxVisible = 3; $start = max(1, $page - 1); $end = min($totalPages, $start + $maxVisible - 1); if ($start > 1): ?> <a href="?page=1">1</a> <?php if ($start > 2): ?><span class="ellipsis">...</span><?php endif; ?> <?php endif; ?> <?php for ($i = $start; $i <= $end; $i++): ?> <?php if ($i == $page): ?> <span class="current"><?= $i ?></span> <?php else: ?> <a href="?page=<?= $i ?>"><?= $i ?></a> <?php endif; ?> <?php endfor; ?> <?php if ($end < $totalPages): ?> <?php if ($end < $totalPages - 1): ?><span class="ellipsis">...</span><?php endif; ?> <a href="?page=<?= $totalPages ?>"><?= $totalPages ?></a> <?php endif; ?> <?php if ($page < $totalPages): ?> <a href="?page=<?= $page + 1 ?>">下一页</a> <?php else: ?> <span>下一页</span> <?php endif; ?> <span style="margin-left: 20px;">共 <?= number_format($totalRows) ?> 条记录,<?= $totalPages ?> 页</span> </div> <?php else: ?> <p>该表中没有数据。</p> <?php endif; ?> </body> </html> 增加解封按键解封后type内容改为1
10-09
<?php // 配置数据库连接 $host = 'localhost'; $dbname = 'syxywl.cn_sdk-14'; // 含特殊字符需用反引号包裹 $username = 'root'; $password = 'qq28009618'; $dsn = "mysql:host=$host;dbname=$dbname;charset=utf8mb4"; try { $pdo = new PDO($dsn, $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("数据库连接失败: " . $e->getMessage()); } // 设置分页参数 $limit = 10; $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $page = max(1, $page); $offset = ($page - 1) * $limit; // === 获取主键字段名 === function getPrimaryKey($pdo, $table) { $stmt = $pdo->prepare("DESCRIBE `$table`"); $stmt->execute(); $columns = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($columns as $col) { if ($col['Key'] === 'PRI') { return $col['Field']; // 返回主键字段名 } } return null; // 没有主键 } $primaryKey = getPrimaryKey($pdo, 't_accounts'); if (!$primaryKey) { die("错误:t_accounts 表没有定义主键!"); } // 处理封禁请求 if ($_SERVER['REQUEST_METHOD'] === 'POST') { $pkValue = $_POST[$primaryKey]; try { if ($_POST['action'] === 'ban') { $sql = "UPDATE `t_accounts` SET `type` = 99 WHERE `$primaryKey` = ?"; $stmt = $pdo->prepare($sql); $stmt->execute([$pkValue]); $successMsg = "用户 <strong>" . htmlspecialchars($pkValue) . "</strong> 已成功 <span style='color:red;'>封禁</span>(type=99)!"; } elseif ($_POST['action'] === 'unban') { $sql = "UPDATE `t_accounts` SET `type` = 1 WHERE `$primaryKey` = ?"; $stmt = $pdo->prepare($sql); $stmt->execute([$pkValue]); $successMsg = "用户 <strong>" . htmlspecialchars($pkValue) . "</strong> 已成功 <span style='color:green;'>解封</span>(type=1)!"; } } catch (PDOException $e) { $errorMsg = "操作失败: " . htmlspecialchars($e->getMessage()); } } // 查询总行数 $totalStmt = $pdo->query("SELECT COUNT(*) FROM `t_accounts`"); $totalRows = $totalStmt->fetchColumn(); $totalPages = ceil($totalRows / $limit); // 获取当前页数据(仅 uid, name, type) $stmt = $pdo->prepare("SELECT `uid`, `name`, `type` FROM `t_accounts` LIMIT ? OFFSET ?"); $stmt->bindValue(1, $limit, PDO::PARAM_INT); $stmt->bindValue(2, $offset, PDO::PARAM_INT); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>封禁/解封 t_accounts 用户</title> <style> body { font-family: Arial, sans-serif; margin: 20px; background-color: #f7f7f7; color: #333; } h1 { color: #d32f2f; } table { width: 100%; border-collapse: collapse; margin-top: 20px; background-color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.1); } th, td { border: 1px solid #ddd; padding: 10px; text-align: left; } th { background-color: #333; color: white; } .status-banned { background-color: #ffcdd2; color: #c62828; padding: 2px 6px; border-radius: 3px; font-weight: bold; } .status-normal { background-color: #e8f5e8; color: #2e7d32; padding: 2px 6px; border-radius: 3px; } button.ban { background-color: #d32f2f; color: white; border: none; padding: 5px 10px; cursor: pointer; border-radius: 4px; font-weight: bold; margin-right: 5px; } button.unban { background-color: #2e7d32; color: white; border: none; padding: 5px 10px; cursor: pointer; border-radius: 4px; font-weight: bold; } button:hover { opacity: 0.9; } button[disabled] { background-color: #ccc; cursor: not-allowed; } .pagination { margin: 20px 0; text-align: center; } .pagination a, .pagination span { display: inline-block; margin: 0 3px; padding: 8px 12px; text-decoration: none; border: 1px solid #ccc; background-color: #fff; color: #333; border-radius: 4px; } .pagination a:hover { background-color: #333; color: white; } .pagination .current { background-color: #333; color: white; font-weight: bold; } .msg { padding: 10px; margin: 10px 0; border-radius: 4px; } .msg.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .msg.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } </style> </head> <body> <h1>🔐 用户封禁与解封管理系统</h1> <p>点击按钮可将用户 <code>type</code> 在 <strong>99(封禁)</strong> 和 <strong>1(正常)</strong> 之间切换。</p> <?php if (isset($successMsg)): ?> <div class="msg success"><?= $successMsg ?></div> <?php endif; ?> <?php if (isset($errorMsg)): ?> <div class="msg error"><?= $errorMsg ?></div> <?php endif; ?> <?php if (!empty($rows)): ?> <table> <thead> <tr> <th>Uid</th> <th>Name</th> <th>Status</th> <th>操作</th> </tr> </thead> <tbody> <?php foreach ($rows as $row): ?> <tr> <td><?= htmlspecialchars($row['uid']) ?></td> <td><?= htmlspecialchars($row['name']) ?></td> <td> <?php if ($row['type'] == 99): ?> <span class="status-banned">🔴 已封禁</span> <?php else: ?> <span class="status-normal">🟢 正常</span> <?php endif; ?> </td> <td> <!-- 根据当前 type 显示不同操作按钮 --> <form method="post" style="display:inline;"> <input type="hidden" name="<?= htmlspecialchars($primaryKey) ?>" value="<?= htmlspecialchars($row['uid']) ?>"> <?php if ($row['type'] == 99): ?> <!-- 当前被封禁,提供解封 --> <input type="hidden" name="action" value="unban"> <button type="submit" class="unban" onclick="return confirm('确定要解封用户 UID=<?= $row['uid'] ?> 吗?')"> 解封 </button> <?php else: ?> <!-- 当前正常,提供封禁 --> <input type="hidden" name="action" value="ban"> <button type="submit" class="ban" onclick="return confirm('确定要封禁用户 UID=<?= $row['uid'] ?> 吗?')"> 封禁 </button> <?php endif; ?> </form> </td> </tr> <?php endforeach; ?> </tbody> </table> <!-- 分页导航 --> <div class="pagination"> <?php if ($page > 1): ?> <a href="?page=<?= $page - 1 ?>">上一页</a> <?php else: ?> <span>上一页</span> <?php endif; ?> <?php $maxVisible = 3; $start = max(1, $page - 1); $end = min($totalPages, $start + $maxVisible - 1); if ($start > 1): ?> <a href="?page=1">1</a> <?php if ($start > 2): ?><span class="ellipsis">...</span><?php endif; ?> <?php endif; ?> <?php for ($i = $start; $i <= $end; $i++): ?> <?php if ($i == $page): ?> <span class="current"><?= $i ?></span> <?php else: ?> <a href="?page=<?= $i ?>"><?= $i ?></a> <?php endif; ?> <?php endfor; ?> <?php if ($end < $totalPages): ?> <?php if ($end < $totalPages - 1): ?><span class="ellipsis">...</span><?php endif; ?> <a href="?page=<?= $totalPages ?>"><?= $totalPages ?></a> <?php endif; ?> <?php if ($page < $totalPages): ?> <a href="?page=<?= $page + 1 ?>">下一页</a> <?php else: ?> <span>下一页</span> <?php endif; ?> <span style="margin-left: 20px;">共 <?= number_format($totalRows) ?> 条记录,<?= $totalPages ?> 页</span> </div> <?php else: ?> <p>该表中没有数据。</p> <?php endif; ?> </body> </html> 跨数据库访问db_hk4e_user_gio数据库t_player_uid表 t_player_uid内account_uid对应的是t_accounts表的uid合并显示 同时增加显示t_player_uid表内的UID显示
10-09
<?php // 配置数据库连接 $host = 'localhost'; $dbname = 'syxywl.cn_sdk-14'; // 含特殊字符需用反引号包裹 $username = 'root'; $password = 'qq28009618'; $dsn = "mysql:host=$host;dbname=$dbname;charset=utf8mb4"; try { $pdo = new PDO($dsn, $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("数据库连接失败: " . $e->getMessage()); } // 设置分页参数 $limit = 10; $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $page = max(1, $page); $offset = ($page - 1) * $limit; // === 获取主键字段名 === function getPrimaryKey($pdo, $table) { $stmt = $pdo->prepare("DESCRIBE `$table`"); $stmt->execute(); $columns = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($columns as $col) { if ($col['Key'] === 'PRI') { return $col['Field']; // 返回主键字段名 } } return null; // 没有主键 } $primaryKey = getPrimaryKey($pdo, 't_accounts'); if (!$primaryKey) { die("错误:t_accounts 表没有定义主键!"); } // 处理更新请求 if ($_POST['action'] === 'update') { $pkValue = $_POST[$primaryKey]; // 使用实际主键值 // 获取所有字段 $stmt = $pdo->prepare("DESCRIBE `t_accounts`"); $stmt->execute(); $columns = $stmt->fetchAll(PDO::FETCH_COLUMN); $setParts = []; $params = []; foreach ($columns as $col) { if ($col !== $primaryKey && isset($_POST[$col])) { // 排除主键本身 $setParts[] = "`$col` = ?"; $params[] = $_POST[$col]; } } $params[] = $pkValue; // WHERE 条件:主键 = ? try { $sql = "UPDATE `t_accounts` SET " . implode(', ', $setParts) . " WHERE `$primaryKey` = ?"; $stmt = $pdo->prepare($sql); $stmt->execute($params); echo "<div style='color:green;'>主键为 <strong>$pkValue</strong> 的记录已成功更新!</div>"; } catch (PDOException $e) { echo "<div style='color:red;'>更新失败: " . $e->getMessage() . "</div>"; } } // 查询总行数 $totalStmt = $pdo->query("SELECT COUNT(*) FROM `t_accounts`"); $totalRows = $totalStmt->fetchColumn(); $totalPages = ceil($totalRows / $limit); // 获取当前页数据 $stmt = $pdo->prepare("SELECT * FROM `t_accounts` LIMIT ? OFFSET ?"); $stmt->bindValue(1, $limit, PDO::PARAM_INT); $stmt->bindValue(2, $offset, PDO::PARAM_INT); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // 获取字段名 $columns = empty($rows) ? [] : array_keys($rows[0]); ?> <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>动态编辑 t_accounts 数据表(智能主键)</title> <style> body { font-family: Arial, sans-serif; margin: 20px; background-color: #f7f7f7; } table { width: 100%; border-collapse: collapse; margin-top: 20px; background-color: #fff; } th, td { border: 1px solid #ccc; padding: 10px; text-align: left; } th { background-color: #007BFF; color: white; } input[type="text"], input[type="password"] { width: 100%; padding: 5px; box-sizing: border-box; } button.save { background-color: #28a745; color: white; border: none; padding: 5px 10px; cursor: pointer; } .pagination { margin: 20px 0; text-align: center; } .pagination a, .pagination span { display: inline-block; margin: 0 3px; padding: 8px 12px; text-decoration: none; border: 1px solid #ccc; background-color: #fff; color: #007BFF; } .pagination a:hover { background-color: #007BFF; color: white; } .pagination .current { background-color: #007BFF; color: white; font-weight: bold; } .pagination .ellipsis { color: #999; background-color: transparent; border: none; } </style> </head> <body> <h1>MySQL 数据表:t_accounts(自动识别主键)</h1> <p>本页面自动识别主键字段,支持安全更新。</p> <?php if (!empty($rows)): ?> <table> <thead> <tr> <?php foreach ($columns as $col): ?> <th><?= htmlspecialchars($col) ?></th> <?php endforeach; ?> <th>操作</th> </tr> </thead> <tbody> <?php foreach ($rows as $row): ?> <tr> <form method="post" style="display:inline;"> <input type="hidden" name="action" value="update"> <!-- 主键字段隐藏输入 --> <input type="hidden" name="<?= htmlspecialchars($primaryKey) ?>" value="<?= htmlspecialchars($row[$primaryKey]) ?>"> <?php foreach ($columns as $col): ?> <td> <?php if ($col === 'password'): ?> <input type="password" name="<?= htmlspecialchars($col) ?>" value="<?= htmlspecialchars($row[$col]) ?>" placeholder="保持原密码"> <?php else: ?> <input type="text" name="<?= htmlspecialchars($col) ?>" value="<?= htmlspecialchars($row[$col]) ?>"> <?php endif; ?> </td> <?php endforeach; ?> <td><button type="submit" class="save">保存</button></td> </form> </tr> <?php endforeach; ?> </tbody> </table> <!-- 分页导航 --> <div class="pagination"> <?php if ($page > 1): ?> <a href="?page=<?= $page - 1 ?>">上一页</a> <?php else: ?> <span>上一页</span> <?php endif; ?> <?php $maxVisible = 5; $half = (int)($maxVisible / 2); $start = max(1, $page - $half); $end = min($totalPages, $start + $maxVisible - 1); if ($end - $start + 1 < $maxVisible) { $start = max(1, $end - $maxVisible + 1); } ?> <?php if ($start > 1): ?> <a href="?page=1">1</a> <?php if ($start > 2): ?><span class="ellipsis">...</span><?php endif; ?> <?php endif; ?> <?php for ($i = $start; $i <= $end; $i++): ?> <?php if ($i == $page): ?> <span class="current"><?= $i ?></span> <?php else: ?> <a href="?page=<?= $i ?>"><?= $i ?></a> <?php endif; ?> <?php endfor; ?> <?php if ($end < $totalPages): ?> <?php if ($end < $totalPages - 1): ?><span class="ellipsis">...</span><?php endif; ?> <a href="?page=<?= $totalPages ?>"><?= $totalPages ?></a> <?php endif; ?> <?php if ($page < $totalPages): ?> <a href="?page=<?= $page + 1 ?>">下一页</a> <?php else: ?> <span>下一页</span> <?php endif; ?> <span style="margin-left: 20px;">共 <?= $totalRows ?> 条记录,<?= $totalPages ?> 页</span> </div> <?php else: ?> <p>该表中没有数据。</p> <?php endif; ?> </body> </html> 改为只显示三个分页
10-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值