页面搜索栏上的html / php

时间:2017-03-23 10:21:25

标签: php html

我正在尝试为此网页创建一个有效的搜索栏。基本上,当您输入时,它会将您带到您搜索的文本(类似于CTRL + F)

注意:我希望此搜索栏仅搜索当前页面上的文本。不是所有页面或MYSQL数据库。在页面上,搜索栏已开启。

但问题是无论我使用什么代码,搜索栏上的按钮都会使用与PDF转换器操作相同的表单操作。

这是我试过的代码: http://www.dynamicdrive.com/dynamicindex11/findpage.htm

<html>
<head>
<title>Extension List</title></head><body>
<br>
<h1> Alpine Motors Extension List</h1>
<h2><a href="add.php">Add Extension</a>
<br>
<br>
<form action="AlpineExtensionList.php"  method='post'>
<input type="submit" value="Print PDF"/>
<br>
<br>
<a href="delete.php"> Delete Extension</a></h2>
<br>
<br>

<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '****';

$database = 'list';
$table = 'users';

$conn = mysqli_connect($db_host, $db_user, $db_pwd) or die("Connecting to database failed");

mysqli_select_db($conn, $database) or die("Can't select database");

// sending query
$result = mysqli_query($conn, "SELECT name, email, extension, phone, department FROM {$table} ORDER BY department, name ASC");
if (!$result) {
    die("Query to show fields from table failed");
 }

 echo "<table border='1'><tr>";

// printing table rows
$temp = "";

while($row = mysqli_fetch_array($result))
{
    echo "<tr>";

    if ($row['department'] != $temp){
        echo "<td colspan='4' style='text-align: center; font-weight: bold'>{$row['department']}</td></tr>\n<tr>";

echo "<tr><th>Name</th>
<th>Email</th>
<th>Extension</th>
<th>Phone</th>
</tr>\n"; 
echo "<tr>";

        $temp = $row['department'];
    }

     echo "<td>" . $row['name'] . "</td><td><a href=\"mailto:" . $row['email'] . "\">" . $row['email'] . "</a></td><td>" . $row['extension'] . "</td><td>" . $row['phone'] . "</td>";

    echo "</tr>\n";
}
mysqli_free_result($result);
echo "</table>"
?>


</h2>
</body>
</html>

0 个答案:

没有答案