HAVOCWIZARD Posted June 18, 2007 Share Posted June 18, 2007 guys i have a very confusing question, my search is working so far perfect, but, i do i basic search okey, no result because the search string is let say 2 words, no problem, do my advance search finds the world the use if statement and getting the pefect result, now even 3 words work, but now what happens if i have to search 5 words, how can i make it start search on the back of the string because if have $find= explode(" ", $find); for($loop_keywords = 0; $loop_keywords <= count($find); $loop_keywords++) { //$find[$loop_keywords] = $find[$loop_keywords]; $find1 = $find[$loop_keywords]; the i query each word, when i find the word i go check on the if statement, how can i make this start at the end of the words Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 18, 2007 Share Posted June 18, 2007 Do you think you could explain in a bit more detail what you're trying to achieve? I personally am a bit confused. Also, you'd be far better off naming your topic with a relevant subject. Quote Link to comment Share on other sites More sharing options...
HAVOCWIZARD Posted June 18, 2007 Author Share Posted June 18, 2007 nevermind i confused myself, think i fixed the problem, writing up function, how to i pass values to the function? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 18, 2007 Share Posted June 18, 2007 when you declare your function: function myfunction($var1,$var2,$var3='foobar'){ //function } And when you use you function myfunction($somevar,$someothervar); As you will notice, the third variable in the function definition was given a value. This makes the parameter optional. You can still pass a value for that function, or you can leave it as the default. Quote Link to comment Share on other sites More sharing options...
HAVOCWIZARD Posted June 18, 2007 Author Share Posted June 18, 2007 after i ran the function it doesnt return my result why, here is what i did. function worddisplay($wordcount,$find,$result) { if ($wordcount == 2) { $find1 = $find[1]; $data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'"); //$result = mysql_fetch_array( $data); while ($result = mysql_fetch_array( $data)) { if ($result == "") { $find1 = $find[0]." ".$find[1]; $data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'"); //$result = mysql_fetch_array( $data); while ($result = mysql_fetch_array( $data)) { return ($result); } } else { return ($result = mysql_fetch_array($data)); } } } } worddisplay($wordcount,$find,$result); { echo($result['register_companyName']; } why doesnt it give my result to echo ? Quote Link to comment Share on other sites More sharing options...
HAVOCWIZARD Posted June 18, 2007 Author Share Posted June 18, 2007 tryed both ways as you can see at the end not one of them wants to give my result Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 18, 2007 Share Posted June 18, 2007 Try: <?php function worddisplay($wordcount,$find,$result) { if ($wordcount == 2) { $find1 = $find[1]; $data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'"); //$result = mysql_fetch_array( $data); while ($result = mysql_fetch_array( $data)) { if ($result == "") { $find1 = $find[0]." ".$find[1]; $data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'"); //$result = mysql_fetch_array( $data); while ($result = mysql_fetch_array( $data)) { return ($result); } } else { return (mysql_fetch_array($data)); } } } } $result = worddisplay($wordcount,$find,$result); { echo($result['register_companyName']; } ?> Quote Link to comment Share on other sites More sharing options...
HAVOCWIZARD Posted June 18, 2007 Author Share Posted June 18, 2007 nope doesnt work, tryed all diffrent ways, after the return do i set return as the return or ? ...i have tryed it with return(mysql_fetch_array(data)); but still nothing Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 18, 2007 Share Posted June 18, 2007 you should probably be using the mysql full text search functions.... http://dev.mysql.com/doc/refman/4.1/en/fulltext-search.html formulating your query on teh correct fields will be VASTLY more efficient than using php to search each and every entry for a string an unspecified number of times..... Quote Link to comment Share on other sites More sharing options...
HAVOCWIZARD Posted June 19, 2007 Author Share Posted June 19, 2007 thanks guys for all the help, got it right when search full text then check every field, but i sitting with something else now, is the a limit on mysql query? because it doesnt search on my keywords1. here is what i have. if ($wordcount == 4) { $find1 = $find[3]; $find1 = strtoupper($find1); $find1 = strip_tags($find1); $find1 = trim ($find1); $data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'"); while ($result = mysql_fetch_array( $data)); { if i put in the keyword on its own it works, but if i have four words it seaches on the last word and i checked that word is there, but i goes though to the find==""; function, not good, what can be the problem Quote Link to comment Share on other sites More sharing options...
HAVOCWIZARD Posted June 19, 2007 Author Share Posted June 19, 2007 i just tested it and if remove the while statement it works ??? now im confused just normal result = fetch ...... it works, why Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 19, 2007 Share Posted June 19, 2007 very odd. :-\ 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.