Jump to content

foreach, search, help


mikefrederick

Recommended Posts

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>";
} } }

?>

Link to comment
https://forums.phpfreaks.com/topic/96463-foreach-search-help/
Share on other sites

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'>";?>

Link to comment
https://forums.phpfreaks.com/topic/96463-foreach-search-help/#findComment-493683
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.