我很难链接我的数据库的每一行,以显示将显示另一个mySQL数据库表的链接。我认为错误来自我的代码的第二部分,而不是我的查询可能不正确的第一部分,但我无法弄清楚我需要更改哪一部分。 到目前为止,这些是我的代码:
</tr>
</thead>
<?php
while($row = mysqli_fetch_array($result))
{
$id = $row['my30_rsl_id'];
$SupplierName = $row['SupplierName'];
$Commodity = $row['Commodity'];
echo '
<tr>
<td>'.$row["my30_rsl_id"].'</td>
<td><a href="request.php?id=' . $id . '">' . $SupplierName . '</a></td>
<td><a href="request.php?id=' . $id . '">' . $Commodity . '</a></td>
<td>'.$row["Sub-Category"].'</td>
<td>'.$row["Status"].'</td>
<td>'.$row["Location"].'</td>
</tr>
';
}
?>
</table>
链接所指的页面: (它在$ result返回错误)
<?php
$connect = mysqli_connect("localhost", "root", "password", "database");
$id = $_GET['id'];
$result = mysqli_query($con,"SELECT * FROM my30_rsl WHERE my30_rsl_id = $id");
?>
<!DOCTYPE html>
<html>
<head>
<title>Details</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<br /><br />
<div class="container">
<h3 align="center">Details</h3>
<br />
<div class="table-responsive">
<table id="supplier_data" class="table table-striped table-bordered">
<thead>
<tr>
<td>SupplierName</td>
<td>Comments</td>
</tr>
</thead>
<?php
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td> <a href=#>'.$row["SupplierName"] . '</a> </td>
<td>'.$row["Comments"].'</td>
</tr>
';
}
?>
</table>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$('#supplier_data').DataTable();
});
</script>
答案 0 :(得分:0)
可能是一些命名问题?你的代码带有评论
$connect = mysqli_connect("localhost", "root", "password", "database");
$id = $_GET['id'];
$result = mysqli_query($con,"SELECT * FROM my30_rsl WHERE my30_rsl_id = $id");
// ^--- where does that come from? you only have $connect
因此您可能需要将其命名为$connect
。如果这不是问题,也许您应该查看错误消息,使用搜索引擎查找错误消息并找出错误。
此外,您的代码容易受到sql注入攻击。请了解如何使用准备好的陈述。