paulmo Posted January 14, 2009 Share Posted January 14, 2009 mysql 4.1, phpadmin, myisam, and 'terms' field is text. my search box is matching fine for one word, but not working for multiple words. for example, "yellow" in search box echoes correct table field ('terms') row about a yellow sun, etc. but "yellow dog in the road" in search box echoes "try again." the user will be writing at least one tence, and i need any word in that sentence to echo the matched table field row. the form: <form name="search" method="post" action="beta.php"> <center>Write something: </br></br> <input type="text" name="find" class="buttonsb"/> <input type="hidden" name="searching" value="yes" /></br></br></br> <input type="submit" name="search" value="Process" class="buttons" /> </center> </form> the code: $searching = $_POST['searching']; $find = $_POST['find']; if ($find == "") { echo "Please write something."; exit; } mysql_connect("xxx") or die(mysql_error()); mysql_select_db("xxx") or die(mysql_error()); $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); $data = mysql_query("SELECT * FROM beta WHERE terms LIKE'%$find%'"); while($result = mysql_fetch_array($data)) { echo $result['terms']; echo " "; } $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "try again.<br><br> "; echo "You wrote: " .$find; } ?> thanks for help or suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/ Share on other sites More sharing options...
fenway Posted January 14, 2009 Share Posted January 14, 2009 Sounds like you need to split on spac. Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/#findComment-737032 Share on other sites More sharing options...
paulmo Posted January 14, 2009 Author Share Posted January 14, 2009 wow, guess i should have stated i'm a relative newbie at this; i'd be clueless about what split on spac means, or how to apply that expression to the code i've presented. Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/#findComment-737058 Share on other sites More sharing options...
fenway Posted January 14, 2009 Share Posted January 14, 2009 spac = space with a typo.....i just meant to use LIKE to search on each word in the string. Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/#findComment-737168 Share on other sites More sharing options...
paulmo Posted January 14, 2009 Author Share Posted January 14, 2009 but the form is to search on any word that's submitted (like 100's of words); LIKE is too limiting. any other ideas? thanks Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/#findComment-737187 Share on other sites More sharing options...
fenway Posted January 18, 2009 Share Posted January 18, 2009 Not sure what you mean by "limiting"... it will find any word that matches... Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/#findComment-739710 Share on other sites More sharing options...
paulmo Posted January 25, 2009 Author Share Posted January 25, 2009 ok, i understand. how to split on space in this query? thanks Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/#findComment-746052 Share on other sites More sharing options...
paulmo Posted January 25, 2009 Author Share Posted January 25, 2009 is any of this getting close? $message = strtoupper($message); $message = strip_tags($message); $message = trim ($message); $message = str_split($message); $name = trim ($name); $name = strip_tags($name); $name = mysql_real_escape_string($name); //$message = preg_split("/[\s,]+/") $data = mysql_query("SELECT * FROM xxx WHERE terms LIKE'%$message%'"); while($result = mysql_fetch_array($data)) { echo $result['terms']; echo " "; } Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/#findComment-746067 Share on other sites More sharing options...
fenway Posted January 27, 2009 Share Posted January 27, 2009 Not really.. you need a LIKE for each word. Quote Link to comment https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/#findComment-747538 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.