Jump to content
xisto Community
Sign in to follow this  
darkool

Need Help In Coding A Search Engine How to Use multiple keywords in it ?

Recommended Posts

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

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

<? 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 :)
Edited by microscopic^earthling (see edit history)

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.