duangu3620 2013-03-14 17:43
浏览 101

搜索引擎在自己的网站[关闭]

Hi guys I'm trying to make a search engine in my website. Search engine must browse in a category and after search must display all results. But the engine doesn't display the results.

Example: X user is searching in PC-games for Y game. The X user type in text area the name of game and then click button search. After search script doesn`t display the results of Y game. Here is my script

<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 script

<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>
  • 写回答

1条回答 默认 最新

  • dousi1994 2013-03-14 18:05
    关注

    Here, I'll post that as an answer if you feel you can close this.

    I think your issue is that scandir takes a string argument for the directory, not a file handle.

    As people are saying, you should really take the time to learn more about databases. There are many tutorials available on the web and this is pretty much a required skill to posses for any sort of development. MySQL and PDO is a good place to start.

    Good luck.

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试