大家好,我正在尝试在我的网站上制作搜索引擎。搜索引擎必须在一个类别中浏览,搜索后必须显示所有结果。但是引擎不显示结果。
示例:X 用户正在 PC 游戏中搜索 Y 游戏。X 用户在文本区域输入游戏名称,然后单击按钮搜索。搜索脚本后不显示 Y 游戏的结果。这是我的脚本
<form action="search.php" method="POST">
<p><br />
<input name="q" type="hidden" />
<font color="black">Hunt Data:</font>
<input name="qfront" type="text" style="width: 230px" name="nume"id="nume" />
<select name="category">
<option value="0">All</option>
<option value="1">PC-Games</option>
<option value="2">Console</option>
<option value="3">Movies</option>
<option value="4">Music</option>
<option value="5">XXX</option>
<option value="6">Windows</option>
<option value="7">Linux</option>
<option value="8">Software</option>
<option value="9">Documents</option>
<input type="submit" value="Search" />
</p>
</form>
PHP 脚本
<html>
<body>
<center>
<font color="black" size="4">
<?php
//define each directory here, the index starts with 0 == all and so on.
$categorydir = array('/Category/All/', '/Category/PCGames/', '/Category/Console/', '/Category/Movies/', '/Category/Music/', '/Category/XXX/', '/Category/Windows/', '/Category/Linux/', '/Category/Software/', '/Category/Documents/');
//if option selected and its valid number
if (isset($_POST['category']))
if(ctype_digit($_POST['category']) && isset($categorydir[$_POST['category']])) {
if(array_key_exists($_POST['category'], $categorydir) && is_dir($categorydir[$_POST['category']])) {
$handle = opendir($categorydir[$_POST['category']]); //LINE 14
$files = scandir($handle);
echo 'Results of search:<br></br>';
foreach($files as $file){ //LINE 17
echo($file);
}
} else {
echo 'target directory not found';
}
}
?>
</font>
</center>
</body>
</html>
<html>
<head>
<title>DataHunters</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="header">
<h1 id="logo"><a href="index.html">DataHunters</a>
</h1>
</div>
<div id="navigation">
<ul>
<li><a class="active" href="index.html">Home</li></a>
<li><a href="chat.html">Chat</li></a>
<li><a href="contact.html">Contact</li></a>
<li><a href="http://www.forum.datahunters.ro">Forum</li></a>
</ul>
</li>
</div>
</body>
</html>