我有一个由表单
生成的表单 <?php while ($row = $sth->fetch(PDO::FETCH_ASSOC)): ?>
<tr>
<td><?php echo htmlspecialchars($row['id'])?></td>
<td><a href = "details.php"><?php echo htmlspecialchars($row['type_code']); ?></a></td>
<th><?php echo htmlspecialchars($row['connector_type']); ?></td>
<th><?php echo htmlspecialchars($row['construction_type']); ?></td>
<th><?php echo htmlspecialchars($row['start_passband']); ?></td>
<th><?php echo htmlspecialchars($row['stop_passband']); ?></td>
<th><?php echo htmlspecialchars($row['lower_stopband_start']); ?></td>
<th><?php echo htmlspecialchars($row['lower_stopband_stop']); ?></td>
<th><?php echo htmlspecialchars($row['upper_stopband_start']); ?></td>
<th><?php echo htmlspecialchars($row['upper_stopband_stop']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
正如你所看到的,第二行,type_code链接到另一个页面,“details.php” - 我希望从'type_code'产生的信息中生成该页面。我该怎么做呢?
答案 0 :(得分:-1)
您所要做的就是在网址中传递您的ID:
<a href="details.php?id=<?php echo $row['id']; ?>">link</a>
然后在你的details.php页面中你可以像这样检索数据
$query = "SELECT * FROM table WHERE id = '" . $_GET['id'] . "'";
您显然希望在此基础上添加验证以保护您的网页
if(isset($_GET['id']) && (int)$_GET['id']) {
$query = "SELECT * FROM table WHERE id = '" . $_GET['id'] . "'";
// build your page
} else {
header('Location: index.html'); // or whatever else
}