我正在尝试为每条记录创建单独的链接。 我有两个文件:
的index.php
<?php
$connect = mysql_connect("localhost", "test", "pass");
if (!$connect) {
die("Can not connect:" . mysql_error());
}
mysql_select_db("snippets", $connect);
$ID = '';
if( isset( $_GET['ID'])) {
$ID = $_GET['ID'];
}
$sql = "SELECT * FROM lectures";
$myData = mysql_query($sql, $connect);
while($record = mysql_fetch_array($myData)) {
$ID = $record['ID'];
$Name = $record['Name'];
echo "<div class=\"container\">";
echo "<div class=\"row\">";
echo "<div class=\"col-md-2\">";
echo "<p>$record[ID]</p>";
echo "</div>";
echo "<div class=\"col-md-2\">";
echo "<p>$record[Topic]</p>";
echo "</div>";
echo "<div class=\"col-md-2\">";
echo "<p>$record[Name]</p>";
echo "</div>";
echo "<div class=\"col-md-2\">";
echo "<p>$record[Attendance]</p>";
echo "</div>";
echo "<div class=\"col-md-2\" style=\"display:none;\">";
echo "<p>$record[Topic]</p>";
echo "</div>";
echo "<div class=\"col-md-2\" style=\"\">";
echo "<td> <a href='car.php?id=" . $ID . " '>" . $record['Name'] . "</a> </td>";
echo "</div>";
echo "</div>";
echo "</div>";
}
mysql_close($connect);
?>
car.php
<?php
$connect = mysql_connect("localhost", "test", "pass");
if (!$connect) {
die("Can not connect:" . mysql_error());
}
mysql_select_db("snippets", $connect);
$ID = '';
if( isset( $_GET['ID'])) {
$ID = $_GET['ID'];
}
$sql = "SELECT * FROM lectures WHERE ID = '$ID' ";
$myData = mysql_query($sql, $connect);
while($record = mysql_fetch_array($myData)) {
$ID = $record['ID'];
$Name = $record['Name'];
echo "<div class=\"container\">";
echo "<div class=\"row\">";
echo "<div class=\"col-md-2\">";
echo "<p>$record[ID]</p>";
echo "</div>";
echo "<div class=\"col-md-2\">";
echo "<p>$record[Topic]</p>";
echo "</div>";
echo "<div class=\"col-md-2\">";
echo "<p>$record[Name]</p>";
echo "</div>";
echo "<div class=\"col-md-2\">";
echo "<p>$record[Attendance]</p>";
echo "</div>";
echo "<div class=\"col-md-2\" style=\"display:none;\">";
echo "<p>$record[Topic]</p>";
echo "</div>";
echo "</div>";
echo "</div>";
}
mysql_close($connect);
?>
当我点击链接时,页面为空。如果我在ID = '2'
中放置一个值(例如:2),它就可以了。但这将是所有链接的价值。
答案 0 :(得分:-1)
如果您在linux中工作,您应该在大写情况下编写ID
param,因此您应该替换它:
echo "<td> <a href='car.php?id=" . $ID . " '>" . $record['Name'] . "</a> </td>";
由此:
echo "<td> <a href='car.php?ID=" . $ID . " '>" . $record['Name'] . "</a> </td>";