barkster Posted September 1, 2006 Share Posted September 1, 2006 I'm wanting to split my search keywords on my site into seperate words to increase likelyhood of hit. Does anyone have an example on how to do this or maybe a script that will do something similar. For instance if you search "car blue chevy" that it will return results for a "blue chevy car".Thanks Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 1, 2006 Share Posted September 1, 2006 $key_words = explode(' ',$_GET['keywords']);thats assuming you use the get method and the tet field in your form is called 'keywrods' Quote Link to comment Share on other sites More sharing options...
barkster Posted September 2, 2006 Author Share Posted September 2, 2006 Thanks, any suggestions on building the query string dynamically for the number of items. I know I can get the count of the array but was wondering when I loop through them what the best method for building my mysql query string. Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted September 2, 2006 Share Posted September 2, 2006 try[code]<?php$whereclause = '';$where = array();if ($_GET['keywords']) { $keywords = explode(' ', $_GET['keywords']); foreach ($keywords as $kw) { $kw = get_magic_quotes_gpc() ? trim($kw) : addslashes(trim($kw)); $where[] = "(description LIKE '%$kw%')"; } $whereclause = "\nWHERE " . join (" \nAND ", $where);}$sql = "SELECT id, description FROM mytable $whereclause";echo '<pre>',$sql,'</pre>';?><FORM><input type="text" name="keywords" size="40"><input type="submit" name="submit" value="Search"></FORM>[/code] Quote Link to comment Share on other sites More sharing options...
barkster Posted September 2, 2006 Author Share Posted September 2, 2006 Cool I'll try it out, thanks for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.