我希望能够通过我的搜索引擎获得一些帮助,我正在努力写作
到目前为止,我有两个.php
个文件,一个是index.php
,另一个是search.php
。 index.php
是一个前端网站,用户输入他们想要搜索的内容,搜索结果应该显示在哪里。但是,我认为我的代码不起作用,并且在尝试执行搜索时,我在搜索栏下面编写了很多代码。
以下是代码: 的index.php
<!DOCTYPE html PUBLIC "-//W3C??DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xxhtmll/DTD/xhtmll-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<meta http-eqiv="Content-Type" content="text/html; charset=utf-8" />
<title> Trial Report Database - Home</title>
</head>
<body>
<center>
<h2>CIS TDU Trial Report</h2>
<form action='./search.php' method='get'>
<input type='text' name='k' size='100' />
<input type='submit' value='Search'>
</form>
</center>
</body>
</html>
和search.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xxhtmll/DTD/xhtmll-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<meta http-eqiv="Content-Type" content="text/html; charset=utf-8" />
<title> Trial Report Database - Search</title>
</head>
<body>
<center>
<h2>CIS TDU Trial Report</h2>
<form action='./search.php' method='get'>
<input type='text' name='k' size='100' placeholder='Enter Trial Here...' />
<input type='submit' value='Search' />
</form>
</center>
<hr />
<?php
$k = $_GET['k'];
$terms = explode("", $k);
$query = "SELECT * FROM cistdutrd WHERE keywords='$term1'"
foreach ($terms as $each){
$i++;
if ($i == 1)
$query .= "keywords LIKE '%$each%'";
else
$query .= "OR keywords LIKE '%$each%'";
}
echo $query
//collect
mysql_connect("localhost", "root", "password");
mysql_select_db("cistdutrd");
$query = mysql_query($query);
$numrows = mysql_num_rows($query);
if ($numrows > 0) {
while ($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$TName = $row['Trial Name'];
$TType = $row['Trial Type'];
$TTeam = $row['Trial Team'];
$Date = $row['Date'];
$RHyperlink = $row['Report Hyperlink'];
echo "<h2><a href='$link'>$TName<a/></h2>
$TType<br /><br />";
}
}
else
echo "No results found for \"<b>$k</b>\"";
//disconnect
mysql_close ();
?>
</body>
</html>
任何帮助,为什么这不起作用。这将不胜感激。 非常感谢 添