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. 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. 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. 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. 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 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... 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 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 " "; } 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. 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
Archived
This topic is now archived and is closed to further replies.