-3

您好,我设法将一个简单的搜索引擎作为其基础,所以我开始研究它。但我被禁止访问,不知道为什么有人可以帮助我?用一个表格,我给 $find 我搜索的词,它应该搜索它。谢谢你的时间!`

    <?php

    if ($searching =="yes")  
    {   
    echo "Results";

    if ($find == "")   
    {   
    echo "You forgot to enter a search term";  
     exit;   
    }   
    mysql_connect("localhost","Anton","zouzou13") or die(mysql_error());  mysql_select_db("Ptyxiakh") or  die(mysql_error());
    $find = strtoupper($find);

    $find = strip_tags($find);

    $find = trim ($find);

    $data =mysql_query("SELECT * FROM documents WHERE keywords LIKE'%$find%'");  
     while($result = mysql_fetch_array( $data ))   
    {   
    echo $result['document_name'];   
    echo " ";
    echo $result['first_paragraph'];
    echo "<br>";     
    } 
     $anymatches=mysql_num_rows($data);
    if ($anymatches == 0)   
    {   
    echo "Sorry, but we can not find an entry to match your query<br><br>";   }
     echo "<b>Searched For:</b> " .$find;   }  ?>

ok i made it simpler to see if it works like this:

    <?php
    error_reporting(E_ALL);

    mysql_connect("localhost","Anton","zouzou13") or die(mysql_error()); 
    mysql_select_db("Ptyxiakh") or die(mysql_error()); 


     //Now we search for our search term, in the field the user specified 
     $data = mysql_query("SELECT * FROM documents WHERE keywords LIKE 'helmets'");

      while($result = mysql_fetch_array( $data ))   
    {   
    echo $result['document_name'];   
    echo " ";
    echo $result['first_paragraph'];
    echo "<br>";     
    }

     $anymatches=mysql_num_rows($data); 
     if ($anymatches == 0) 
     { 
     echo "Sorry, but we can not find an entry to match your query<br><br>"; 
     }
    ?> 
But i get the "Sorry, but we can not find an entry to match your query<br><br>"; so i cant connect to database?its just wont work :(



With PDO it should be like this??:

<?php
 //This is only displayed if they have submitted the form 
 if ($searching =="yes") 
 { 
 echo "<h2>Results</h2><p>"; 

 //If they did not enter a search term we give them an error 
 if ($find == "") 
 { 
 echo "<p>You forgot to enter a search term"; 
 exit; 
 } 
 $pdo = new PDO('mysql:host=localhost;dbname=ptyxiakh', 'Anton', 'zouzou13');
 // Otherwise we connect to our Database 
//mysql_connect("localhost","Anton","zouzou13") or die(mysql_error()); 
//mysql_select_db("Ptyxiakh") or die(mysql_error()); 

 // We preform a bit of filtering 
 $find = strtoupper($find); 
 $find = strip_tags($find); 
 $find = trim ($find); 

 //Now we search for our search term, in the field the user specified 
 //$data = mysql_query("SELECT * FROM documents WHERE keywords LIKE'%$find%'"); 
 $data= $pdo->query("SELECT * FROM documents WHERE keywords LIKE'%$find%'");

 //And we display the results 
 while($row = $statement->fetch(PDO::FETCH_ASSOC)) 
 { 
 echo htmlentities($row['document_name']); 
 echo " "; 
 echo htmlentities($row['first_paragraph']);
 echo "<br>";   
 } 

 //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 { 
 echo "Sorry, but we can not find an entry to match your query<br><br>"; 
 } 

 //And we remind them what they searched for 
 echo "<b>Searched For:</b> " .$find; 
 } 
?> 
4

1 回答 1

0

我让它工作得非常基本,我猜它已经弃用了thingys,但我上传了用于搜索东西的ppl......只需制作一个简单的表格,然后制作一个php文件

    <?php
 error_reporting(E_ALL);
 //This is only displayed if they have submitted the form 
 echo "<h2>Results</h2><p>"; 
 $find =$_POST["find"];
 //If they did not enter a search term we give them an error 
 if ($find == "") 
 { 
 echo "<p>You forgot to enter a search term"; 
 exit; 
 } 
 // Otherwise we connect to our Database 
 mysql_connect("localhost","Anton","zouzou13") or die(mysql_error()); 
 mysql_select_db("Ptyxiakh") or die(mysql_error()); 

 // We preform a bit of filtering 
 $find = strtoupper($find); 
 $find = strip_tags($find); 
 $find = trim ($find); 

 //Now we search for our search term, in the field the user specified 
 $data = mysql_query("SELECT * FROM documents WHERE keywords LIKE'%$find%'"); 

 //And we display the results 
  while($result = mysql_fetch_array( $data ))   
    {
    echo '<p> <strong>',$result['document_name'], '</strong> <br> ', $result['first_paragraph'],'... <br> </p>';
    }

 //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 { 
 echo "Sorry, but we can not find an entry to match your query<br><br>"; 
 } 

 //And we remind them what they searched for 
 echo "<b>Searched For:</b> " .$find; 

?> 

这对我有用:) thx!

于 2012-12-28T22:39:10.267 回答