Jump to content

search multiply words


Katie

Recommended Posts

Hiya, can I ask does anyone think this script can be adjusted so it can search for two keywords rather then one. I've tried but no luck, could someone show me how its done

 

 

someone told me to this ------------------------

 

$sql = "SELECT whatever, more, stuff FROM table WHERE ";

 

$keywordArray = explode(" ", $_POST['keyword']);

 

foreach ($keywordArray As $val) {

    $sql .= "(keyword LIKE '".$val."') ";

}

 

Then you will need to make sure the SQL is either doing an AND or OR search by replacing the )( that are rendered into ) AND ( or ) OR (

 

$sql = str_replace(") (", ") AND (", $sql);

 

$sql .= "LIMIT 25;";

 

-------------------

 

how would i put that into this code

----------------------------------------

 

<?

 

print "<html><head><title>My Search Engine</title></head><body>\n";

 

if( $_POST['keyword'] )

 

{

 

  include("dbconnect.php");

 

  /* Get timestamp before executing the query: */

 

  $start_timer = timestamp();

 

 

 

  /* Set $keyword and $results, and use addslashes() to

 

    *  minimize the risk of executing unwanted SQL commands: */

 

  $keyword = addslashes( $_POST['keyword'] );

 

  $results = addslashes( $_POST['results'] );

 

 

 

  /* Execute the query that performs the actual search in the DB: */

 

  $result = mysql_query(" SELECT p.webpage_url AS url,

 

                          COUNT(*) AS spidercounts

 

                          FROM webpage p, word w, spidercount o

 

                          WHERE p.webpage_id = o.webpage_id AND

 

                          w.word_id = o.word_id AND

 

                          w.word_word = \"$keyword\"

 

                          GROUP BY p.webpage_id

 

                          ORDER BY spidercounts DESC

 

                          LIMIT $results" );

 

 

 

  /* Get timestamp when the query is finished: */

 

  $stop_timer = timestamp();

 

      $number = mysql_num_rows($result);

 

      if ($number != "0") {

        /* Present the search-results: */

 

        print "<h2>Search results for '".$_POST['keyword']."':</h2>\n";

 

        for( $i = 1; $row = mysql_fetch_array($result); $i++ )

 

        {

 

            print "$i. <a href='".$row['url']."'>".$row['url']."[/url]\n";

 

            print "(spidercount: ".$row['spidercounts'].")

 

\n";

 

        }

 

      } else {

        print "<p>Sorry no matching results found</p>";

      }

 

  /* Present how long it took the execute the query: */

 

  print "query executed in ".(substr($stop_timer-$start_timer,0,5))." seconds.";

 

}

 

function timestamp()

{

 

  list($usec, $sec) = explode(" ",microtime());

 

  return ((float)$usec + (float)$sec);

}

 

 

 

?>

----------------------------------

 

thanks for help and time

Link to comment
https://forums.phpfreaks.com/topic/44743-search-multiply-words/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.