我制作了这个 Printers.php 页面,其中列出了数据库中的所有信息。我有一个模板文件printerbymodel.php,其中列出了单台打印机的信息。基本上我被卡住的地方是如何单击列出的打印机之一并被带到printerbymodel.php页面。
这是我的页面
打印函数.php
function getPrinters2() {
$query = mysql_query("SELECT * FROM printers") or die (mysql_error());
if (mysql_num_rows($query) == 0) {
echo "<tr><td colspan=\"3\">No Printers Were Found</td></tr>";
} else {
while($post = mysql_fetch_assoc($query)) {
$bran=$post['Brand'];
$mod=$post['Model'];
$off=$post['Office'];
$loc=$post['Location'];
$ip=$post['IPAddress'];
$mac=$post['MACAddress'];
$Ink=$post['Ink'];
$Stock=$post['Stock'];
$id=$post['id'];
echo "<tr><td>" . $bran . "</td><td>" . '<a href="/web/printer%202/printer/admin/printerbymodel.php?id='.$post['Model'].'">'.$post['Model'].'</a>' . "</td><td>" . $off . "</td><td>" . $loc . "</td><td>" . $ip . "</td><td>" . $mac. "</td><td>" . $Ink . "</td><td>" . $Stock . "</td><td><a href=\"delete.php?id=" . $id . "\">Delete</a><br /><a href=\"edit.php?id=" . $id . "\">Edit</a></td></tr>";
}
}
}
Printerbymodel.php
<?php
mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error());
mysql_select_db("whc_tech");
$result = mysql_query("SELECT id, Brand, Model, Office, Location, IPAddress, MACAddress, Ink FROM printers");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bran = $row['Brand'];
$mod = $row['Model'];
$off = $row['Office'];
$loc = $row['Location'];
$ip = $row['IPAddress'];
$mac = $row['MACAddress'];
$Ink = $row['Ink'];
}
mysql_free_result($result);
?>
<html>
<head>
<title><?php echo $mod ?></title>
</head>
<body>
<table>
<tr>
<td>Brand</td><td><?php echo $bran; ?></td>
</tr>
<tr>
<td>Model:</td><td><?php echo $mod; ?></td>
</tr>
<tr>
<td>Office:</td><td><?php echo $off; ?></td>
</tr>
<tr>
<td>Location:</td><td><?php echo $loc; ?></td>
</tr>
<tr>
<td>IP Address:</td><td><?php echo $ip; ?></td>
</tr>
<tr>
<td>MAC Address:</td><td><?php echo $mac; ?></td>
</tr>
<tr>
<td>Ink Type:</td><td><?php echo $Ink; ?></td>
</tr>
</table>
</body>
</html>
打印机.php
<?php include('includes/PrintFunctions.php');?>
<html>
<head>
<title>Printer List</title>
</head>
<body bgcolor="f8e2e2">
<style type="text/css">
table.sample {
border-width: 1px;
border-spacing: 5px;
border-style: outset;
border-color: black;
border-collapse: separate;
background-color: rgb(250, 240, 230);
}
table.sample th {
border-width: 1px;
padding: 1px;
border-style: dotted;
border-color: gray;
background-color: rgb(255, 250, 250);
-moz-border-radius: ;
}
table.sample td {
border-width: 1px;
padding: 1px;
border-style: dotted;
border-color: gray;
background-color: rgb(255, 250, 250);
-moz-border-radius: ;
}
</style>
<table class="sample" align="center">
<thead>
<tr>
<td><b>Brand</b></td>
<td><b>Model</b></td>
<td><b>Office</b></td>
<td><b>Location</b></td>
<td><b>IP Address</b></td>
<td><b>MAC Address</b></td>
<td><b>Ink Type</b></td>
<td><b>Ink Stock</b></td>
<td><b>Action</b></td>
</tr>
</thead>
<tbody>
<?php
getPrinters2();
?>
</tbody>
</table>
?>
</body>
</html>
现在,当将打印机信息添加到数据库中时,它们会在 printers.php 中列出,并且模型是一个超链接,这是我卡住的地方。当我点击它时完全迷失了,我将被带到该特定打印机的printerbymodel.php页面,该页面将显示信息。提前致谢。