我已經使這個Printers.php頁面列出了數據庫中的所有信息。 我有一個模板文件printerbymodel.php,它列出了單個打印機的信息。 基本上我被卡住的地方是我如何點擊列出的打印機之一併被帶到printerbymodel.php頁面。PHP幫助獲取數據
這裏是我的網頁
PrintFunctions.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>
Printers.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頁面,該頁面將顯示信息。提前致謝。
我讀了3次,我仍然不知道真正的問題是什麼。但是如果我說得對,我認爲這是一個廣泛的問題。 – Shoe 2013-03-24 23:43:51
您的代碼爲printerbymodel.php在哪裏? – SomeSillyName 2013-03-24 23:47:23
好吧,基本上我希望能夠點擊列出打印機型號的型號。我希望能夠轉到頁面,它將從數據庫中爲該特定模型提供所有信息。 – user2202924 2013-03-24 23:48:38