-1

我制作了这个 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页面,该页面将显示信息。提前致谢。

4

2 回答 2

0

请参阅您发布的 print functions.php 的第 16 行,它正在回显一个包含有关 1 台打印机信息的表格行,请关注这部分:

'<a href="/web/printer%202/printer/admin/printerbymodel.php?id='. $post['Model'].'">'.$post['Model'].'</a>'

(1)我怀疑这是错误的,因为它设置了id=model,所以改变这一行,看看***在哪里进行改变!

'<a href="/web/printer%202/printer/admin/printerbymodel.php?id='. $post[***'id'].'">'.$post['Model'].'</a>'

(2) 现在,这正在创建一个链接,如:printerbymodel.php?id=1234。中printerbymodel.php,您现在需要从 url 中获取该 id

if (isset($_GET['id']) $id = $_GET['id'];

(3) 然后,从数据库中提取记录:

$sql = "SELECT * FROM printers WHERE id=$id";

// get the record from your db by committing $sql
// read the result and echo it.   
于 2013-03-25T00:13:52.967 回答
0

我不是 100% 确定您要的是什么,但我猜您是在询问如何对 printerbymodel.php 进行编码以输出特定模型?

在 printers2() 中,您创建了超链接,如下所示:

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>";

您应该将 id 更改为指向当前记录(而不是模型)的实际 Id,如下所示:

echo "<tr><td>" . $bran . "</td><td>" .  '<a href="/web/printer%202/printer/admin/printerbymodel.php?id='.$post['id'].'">'.$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>";

我认为您应该将变量名 $post 更改为其他名称,因为它很容易与 $_POST 混淆...

你必须做这样的事情(修改一些你现有的getPrinter2()。(我没有做任何验证或任何......)

打印机模型.php

<?php
$id=$_GET['id']; //Got from hyperlink

getPrintersInfo($id);
function getPrintersInfo($id) {
    $query = mysql_query("SELECT * FROM printers WHERE id=$id") 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'];

    //Output information about this specific product...
    echo 'id=' . $id . '<br />';
    echo 'Model=' . $mod; 
    //etc...
}
}
}
于 2013-03-25T00:02:29.260 回答