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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.