mikefrederick Posted March 17, 2008 Share Posted March 17, 2008 hey I am making a search function that is currently producing correctly if you search for one word. if you search for two words, it is showing up any strings that return either word in the search, and if a string contains both words then it shows up twice. I need help fixing this....thanks for looking: <?php $query=mysql_query("select * from whatever order by whatever"); while($sql=mysql_fetch_assoc($query)) { $explode=explode(" ",$sql['description']); $extitle=explode(" ",$sql['title']); $startss=$sql['start']; $startss=explode("-",$startss); $startss=mktime(0,0,0,$startss[1],$startss[2],$startss[0]); $startsss=date('F j, Y',$startss); $endss=$sql['end']; $endss=explode("-",$endss); $endss=mktime(0,0,0,$endss[1],$endss[2],$endss[0]); $endsss=date('F j, Y',$endss); $new=$extitle+$explode; $explodesearch=explode(" ",$search); $i==0; foreach ($new as $currItem) { for($u=0; $u<=count($explodesearch); $u++) { if (strtoupper($explodesearch[$u]) == strtoupper($currItem)){ print "<tr><td align='center' class='daytime' width='20%'>$startsss</td>"; } } } ?> Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted March 17, 2008 Author Share Posted March 17, 2008 I fixed the repetition with the following code, now I just need the results to only show up if they contain ALL of the different words in the searches... <?php foreach ($new as $currItem) { for($u=1; $u<=count($explodesearch); $u++) { $test.="strtoupper($explodesearch[$u]) == strtoupper($currItem) &&"; } if (strtoupper($explodesearch[0]) == strtoupper($currItem) && $test){ $i=$i+1; print "<tr><td align='center' class='daytime' width='20%'>$startsss</td><td align='left' class='daytitle' style='padding-left:10px'>";?> 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.