Say i wanted to search a table with multiple values separated by spaces.

Say

Brand Colour


Dulux Red Green Blue

Crown Pink Red Yellow

So searching red would return


Dulux Red
Crown Red


or searching red pink

Duluz Red
Crown Red Pink.

Recommended Answers

All 9 Replies

Say you finish asking a question...

I had a browser crash for no reason , what happened i don't know.

Using php im trying to figure out a search query where you can type into a search box a phrase say , red pink. It will then search the table and return the results.
Say crown has both red and pink so displays the dulux but crown only has pink so only displays pink.

Dulux pink , red
Crown red

go to w3schools.com and go to the php section and start learning. Then come back with what you have.

I know php , i'm asking because i couldn't remember the phrase to describe what i needed a boolean search. Its the spaces im having trouble with.

This for example should work but every time the for m is submitted nothing happens..

<?php

 
    if ($c != 1) {

?>

<form action="search.php?c=1" method=POST>

<b>Find Results with: </b><br>

Any of these words: <input type="text" length=40 name="any"> <br>

All of these words: <input type="text" length=40 name="all"> <br>

None of these words: <input type="text" length=40 name="none"> <br>

<input type="submit" value="Search">

</form>

<?

  } else if ($c==1) {

   MySQL_connect("localhost", "root", "");

       MySQL_select_db("search");

   if((!$all) || ($all == "")) { $all = ""; } else { $all = "+(".$all.")"; }

   if((!$any) || ($any == "")) { $any = ""; } 

   if((!$none) || ($none == "")) { $none = ""; } else { $none = "-(".$none.")"; }

   $query = "

       SELECT *,

          MATCH(title, body) AGAINST ('$all $none $any' IN BOOLEAN MODE) AS score 

          FROM articles

       WHERE MATCH(title, body) AGAINST ('$all $none $any' IN BOOLEAN MODE)";

      $artm1 = MySQL_query($query);

      if(!$artm1) { 

         echo MySQL_error()."<br>$query<br>"; 

      }

      echo "<b>Article Matches</b><br>";

      if(MySQL_num_rows($artm1) > 0) {

         echo "<table>";

          echo "<tr><td>Score </td><td>Title </td><td>Body</td></tr>";

             while($artm2 = MySQL_fetch_array($artm1)) {

            $val = round($artm2['score'], 3);

            $val = $val*100;

            echo "<tr><td>$val</td>";

            echo "<td>{$artm2['title']}</td>";

            echo "<td>{$artm2['body']}</td></tr>";

         }

      echo "</table>";

   }

   else { 

      echo "No Results were found in this category.<br>"; 

   }

   echo "<br>"; 

   }
  ?>
Member Avatar for diafol

For what appears to be a simple task, the code accompanying it seems to be extremely difficult to follow. No offence. This one's gonna take a little time to process...

how is the table set up is it one column for brand and another for colors or are the colors all separate or is everything in one field ?

I've found a better way of doing this i think ill re post later on.

I think MATCH AGAINST is my best option

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.