php - 无需用户输入自动获取数据库值
问题描述
我正在制作一个获取我所有数据库值的页面。我希望页面自动从数据库中获取 Driver_id 和 Vehicle_id 的值,用户需要知道自己的 id 和 key 是什么。但我被困在这里。
我使用的工具是 phpMyAdmin。
下面是我的表格代码:
<!doctype html>
<html>
<style>
<table>
<th>Vehicle ID</th>
<th>Vehicle Model</th>
<th>Vehicle Color</th>
<th>Plate Number</th>
<th>Seats</th>
<th>Driver ID</th>
<th> </th>
<?php
$link=mysqli_connect("localhost","root","","jomsewa");
mysqli_select_db($link,"jomsewa") or die(mysqli_error($link));
$select = "SELECT * FROM vehicle";
$row = mysqli_query($link,$select);
while ($array = mysqli_fetch_array($row)){
echo "<tr><td>".$array['Vehicle_id']."</td>
<td>".$array['Vehicle_model']."</td>
<td>".$array['Vehicle_color']."</td>
<td>".$array['Vehicle_model']."</td>
<td>".$array['Vehicle_seats']."</td>
<td>".$array['Driver_id']."</td>
<td><a href='Dmaintenance.php?Driverid=".$array['Driver_id']."'>Select</a></td>"."</tr>";
}
mysqli_close($link);
?>
</table>
</body>
</html>
该链接链接到 Dmaintenance.php:
<?php
$link=mysqli_connect("localhost","root","","jomsewa");
if (!$link)
{
echo "Failed to connect to database: " . mysqli_connect_error();
}
mysqli_select_db($link,"jomsewa") or die(mysqli_error($link));
?>
<h3>Please update your maintenance details in the form below.</h3>
<form action="maintenance.php" method="post">
<fieldset>
<legend>Vehicle Maintenance Information:</legend>
<table cellpadding="10">
<tr>
<td>
<?php
if(isset($GET['Driver_id']))
{
$txt = $GET['Driver_id'];
while($row = mysqli_fetch_array($result))
{
echo "<td>".$row['Vehicle_id']."</td>";
echo "<td>".$row['Driver_id']."</td>";
}
}?></td>
</tr>
我想要的是当单击下一页上的一个特定行链接时,它必须自动显示我选择的行内容。
解决方案
使用$_GET['Driverid]
代替$_GET['Driver_id]
没有 SQL 查询Dmaintenance.php
来获取基于Driverid
. 应该有
$query = "SELECT * FROM vehicle WHERE Vehicle_id=".$_GET['Driverid'];
$row = mysqli_query($link,$query);
while ($array = mysqli_fetch_array($row)){
print_r($array);
}
例如
<a href="Dmaintenance.php?Driverid=123">Click Here</a>
并且仅使用以下 in Dmaintenance.php
,您将看到参数值
if(isset($_GET['Driverid'])){
echo $_GET['Driverid'];
}
推荐阅读
- javascript - Django按钮类forloop触发javascript
- javascript - 单击一个按钮并在 django 中使用 JS/ajax 从views.py 运行一个python 函数
- codeigniter - 为什么 Codeigniter 在表单操作中自动添加 .html?
- python - 我无法让 INSERT INTO 表名等在 Python 3.8 pyodbc MySQL 中工作
- mongodb - Mongo读取大量数据
- php - PHP MySQLi更改为PDO时Android登录失败
- java - 使用 Kafka Stream 中的 State-store(RocksDB) 将一条记录转换为多条记录
- arrays - 将自定义排序应用于打字稿中的对象数组
- ios - Xcode 更新不支持 iphone 5s
- entity-framework-core-3.0 - 如何从 ExecuteSqlInterpolatedAsync 获取查询结果?