Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Need Help In Coding A Search Engine, How to Use multiple keywords in it ?
darkool
post Oct 20 2005, 03:25 PM
Post #1


Advanced Member
Group Icon

Group: Members
Posts: 113
Joined: 12-April 05
From: Portugal
Member No.: 3,891



i've a problem, i have a search engine and i can't get him multiple keywords.
When i search in the search engine he only browse for one specific keyword. how can i do a script to let me insert multiple keywords. theres the code

CODE

// This is the module for the forms to insert data in the search engine.

<?
 $add_nome = $_POST[add_nome];
 $add_keywords = $_POST[add_keywords];
 $add_desc = $_POST[add_desc];
 $add_url = $_POST[add_url];
 
 
 if ( $add_nome == '') {
   echo ("<font face='verdana' size='1' color='336699'>Por favor insira o Nome</font>");
}
 else {
 if ($add_keyword == '') {
     echo ("<font face='verdana' size='1' color='336699'>Por favor insira a palavra chave</font>");
}

 else {
 if ($add_desc == '') {
     echo ("<font face='verdana' size='1' color='336699'>Por favor insira a descrição do site</font>");
}

 else {
 if ($add_url == '') {
    echo ("<font face='verdana' size='1' color='336699'>Por favor o URL</font>");
}

else {

 $add = "INSERT INTO $db (nome,keywords,descricao,url) VALUES ('$add_nome','$add_keywords','$add_desc','$add_url')";
 include ("..\sql.php");
 $insert = mysql_query($add,$conn);
 
 echo "<div align='center'><font face='verdana' size='1' color='336699'> <b>$add_nome</b> foi adicionado com sucesso á base de dados.</font></div>";

 mysql_close();

}



Now the script to get the results

CODE


<?

include ("sql.php");

$keywords = $_POST[goget_fetch];

if ($keywords == '') {
  echo "<div align='center'><font face='verdana' size='1' color='336699'>Introduza o tema que deseja procurar</div></font>";
}
 else {

      echo "<table align='center' width='300' height='20' border='0'>";
                        echo "<tr><td>";
                        echo "<font face='verdana' size='1' color='336699'><b>R</b>esultados da pesquisa: <b> $keywords</b></font>";
                        echo "</td></tr></table><br><br>";

     // Query
     $query="SELECT * FROM $db WHERE ( INSTR( keywords, $keywords) >0) LIMIT 0 , 15 ";
       $result=mysql_query($query);

               $num=mysql_fetch_rows($result);

                                     $i=0;
                                        while ($i < $num) {

                                        $nome=mysql_result($result,$i,"nome");
                                        $descricao=mysql_result($result,$i,"descricao");
                                        $url=mysql_result($result,$i,"url");

                       

                        echo "<table align='center' width='300' height='40' border='0'>";
                        echo "<tr><td>";
                        echo "<font face='verdana' size='2' color='336699'><b>$nome</b></font><br><font face='verdana' size='1' color='336699'>$descricao<br><a href='http://$url'>$url</a></font>";
                        echo "</td></tr></table><br>";
                        }
                   
mysql_close();
};
?>


Please give me a help biggrin.gif

This post has been edited by microscopic^earthling: Oct 21 2005, 03:54 PM
Go to the top of the page
 
+Quote Post
ruben
post Oct 22 2005, 10:37 PM
Post #2


Wheeeeeeee!
Group Icon

Group: Members
Posts: 245
Joined: 19-October 05
From: DG, Belgium
Member No.: 9,200



>i've a problem, i have a search engine and i can't get him multiple keywords.
> When i search in the search engine he only browse for one specific keyword. how can i do a >script to let me insert multiple keywords. theres the code

sorry man, I dont know if I got you right:
You want to search your database, if it matches with more than one keyword?
For example:
Database-Entry: Name: one, keywords: bla blu
Database-Entry: Name: two, keywords: blu blo
Database-Entry: Name: three, keywords: blu blo

You want the one with "blu" and "blo" as keywords.
If you search for "blo blu" now, it won't find anything if I understood your script right, because there is no value "blo blu" in there.
What you have to do: explode() the search string, so you get an array. Then you search for each term from the array inside your database and afterwards you give out only those that match both.
I can't write this for you because your site is Spanish and I'll mess around because I do not understand the purpose. If you are not a complete PHP noob, you'll manage.
You should look up the function explode on php.net
You have to explode for spaces " "

I marked the places in your code.

CODE


<?

include ("sql.php");

$keywords = $_POST[goget_fetch]; // here you should write instead explode($_POST[goget_fetch]," ") this will make $keywords an array

if ($keywords == '') {
  echo "<div align='center'><font face='verdana' size='1' color='336699'>Introduza o tema que deseja procurar</div></font>";
}
 else {

      echo "<table align='center' width='300' height='20' border='0'>";
                        echo "<tr><td>";
                        echo "<font face='verdana' size='1' color='336699'><b>R</b>esultados da pesquisa: <b> $keywords</b></font>";
                        echo "</td></tr></table><br><br>";

     // Query
     $query="SELECT * FROM $db WHERE ( INSTR( keywords, $keywords) >0) LIMIT 0 , 15 ";
       $result=mysql_query($query); // you have to do this for each value in the array $keywords

               $num=mysql_fetch_rows($result); // here you can filter out those who didnt get all keywords matched.

                                     $i=0;
                                        while ($i < $num) {

                                        $nome=mysql_result($result,$i,"nome");
                                        $descricao=mysql_result($result,$i,"descricao");
                                        $url=mysql_result($result,$i,"url");

                       

                        echo "<table align='center' width='300' height='40' border='0'>";
                        echo "<tr><td>";
                        echo "<font face='verdana' size='2' color='336699'><b>$nome</b></font><br><font face='verdana' size='1' color='336699'>$descricao<br><a href='http://$url'>$url</a></font>";
                        echo "</td></tr></table><br>";
                        }
                   
mysql_close();
};
?>


I hope you understood, I don't know how good your English and your PHP-skills are. Feel free to ask back, but be sure to inform your self at php.net/explode

good luck,
ruben
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL & PHP coding(9)
  2. Need Help With Multiple Keywords In A Search Engine(5)
  3. PHP Coding Help!(5)


 



- Lo-Fi Version Time is now: 11th October 2008 - 06:05 PM