-2
我有一个网站的标签5下拉菜单。我在MS SQL Server中有一个数据库表。该表包含5个下拉列表的所有数据,其中一个字段名称为Region_Name,例如Region_Names分别为A,B,C,D和E.我编写了代码来显示一个表并为其中一个RegionNames启用行编辑。现在,我想知道是否可以修改相同的代码,以在单击下拉菜单时使用不同查询启用行编辑以显示关联的表格。这可以减少代码重复并提高性能。但我不知道如何实现这一点。任何人都可以给我一些提示吗?我正在使用PHP PDO连接到数据库。如何在SQL下拉菜单中显示单个表?
我的显示表格的代码如下所示。我使用Datatables插件和tableExport Jquery插件。为了简单起见,我没有复制插件的链接和库。如果这会有帮助,我可以显示我的edit.php。
<?php
require_once('include/database.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Matrix</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta http-equiv="content-type" content="text/html" charset="UTF-8">
<script src="//code.jquery.com/jquery-1.12.3.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<header>
</header> <br/>
<div id="container">
<table id="myTable" class="display" cellpadding="0px" cellspacing="0px"
width="100%">
<thead>
<tr>
<th style="width: 1px">ID</th>
<th style="width: 1px">Site</th>
<th style="width: 1px">Location</th>
<th style="width: 1px">Remarks</th>
<th width="1px">Action</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $conn->prepare("SELECT * FROM MATRIX WHERE
Region_Name='Charlotte'");
$stmt ->execute();
$result = $stmt->fetchAll();
foreach($result as $row) {
?>
<tr>
<td><?=$row['ID'];?></td>
<td><?= $row['Site']; ?></td>
<td><?= $row['Location']; ?></td>
<td><?= $row['Remarks']; ?></td>
<td><a href="edit.php?id=<?= $row['ID']; ?>"> Edit</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<br/>
</div>
</body>
</html>
向我们展示你的代码?你取得了什么成就? – Cagy79
*任何人都可以给我一些提示吗?*显示你的代码... – JustOnUnderMillions
我刚添加了我的代码简化版本来显示单个表。 –