Jump to content

Recommended Posts

Hi Guys,

 

in my search if i do 1 word say: graham it searches and find it ok but if there is characters in between them say

 

graham-another word.another word the characters after the work seem to bring back no results

 

basically i just need to search the word graham to get results the minute i put 2 or more words together the reults bring back nothing

 

is there a way to be able to search multiple words?

 

code: part of the query

 

$search_query .= "WHERE (`file_name` LIKE '%$keywords%' OR `file_name` LIKE '%$keywords%')";

 

cheers

 

Graham

 

 

Link to comment
https://forums.phpfreaks.com/topic/65102-search-function/
Share on other sites

I would do:

(index.php?search=Search%20Function)

$keywords=$_GET['search'];
$keywords=trim($keywords);
$result=mysql_query("SELECT * FROM $table WHERE words LIKE '$keywords');
$num=mysql_numrows($result);
echo "Results: $num";
while($results=mysql_fetch_array($result))
{
  print "<tr class='alt'><td><a href='URL'>$results[FIELD]</a></td></tr>";
}

 

etc... I'm not very good at PHP so i'm probably wrong, but hope it helps :D

Link to comment
https://forums.phpfreaks.com/topic/65102-search-function/#findComment-324918
Share on other sites

Split the keyword string into a word array by using PHP's strtok() or explode(). Then like so:

<?php
// Say the words are in $keyword_array...
$search_query = "WHERE (";
for($i=0;$i<count($keyword_array)-1;$i++) $search_query .= "'file_name' LIKE '%".$keyword_array[$i]."%' ";
$search_query .= "'file_name' LIKE '%".$keyword_array[count($keyword_array)-1]."%')";
?>

Hope that helps.

 

Note: The code in the post above is BAD for security!!!

Link to comment
https://forums.phpfreaks.com/topic/65102-search-function/#findComment-324923
Share on other sites

Hi Guys,

 

yeah it searches for 1 word in the string but not multiple

 

hello_there

 

it will only find hello or there

 

hello there

 

this is fine no _ or any other characters confusing it it will find all this

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/65102-search-function/#findComment-324946
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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