Page 1 of 1

Search query - how do I ...

Posted: Fri Dec 17, 2004 9:40 am
by rp
Hi folks

It's "this dumb person" back again - I'm thinking of adding a signature something like "I know it can be done - I just don't know how"

Anyhow this (I hope) is not too taxing. The following query actually works!!

Code: Select all

<?php
$item = explode(' ',$_POST['skillfield']);
print_r ($item);
echo "<p>";
//get number of words
$count = count($item);
echo "<br>";
print $count;
echo "<p>";
for ($i=0; $i <count($item); $i++) 
 if (isset($item[$i]))
 {
$sql = "SELECT * FROM allquals WHERE Qualification LIKE '%$item[$i]%'";
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC))
{
echo $row['Qualification'];
echo " ";
echo $row['QNo'];
echo "<br>";
}
}
}
?>
BUT
how can I "remove" the useless words from the array - i.e. those words like in, a, the, etc.

Because when the search is done naturally it returns matches against all the words without ignoring the in,a,the's etc.

Your help much appreciated but to pls help me, remember I am only a fool who gets things to work by complete trial and error and not by knowing what I am actually doing :oops: :oops:

Posted: Fri Dec 17, 2004 9:53 am
by Weirdan

Code: Select all

<?php
$item = explode(' ', $_POST['skillfield']);
print_r ($item);
echo "<p>";

//get number of words
$count = count($item);
echo "<br>";
print $count;
echo "<p>";

$skip_words = array('in', 'a', 'the', 'blah', 'blah', 'blah....');

for ($i=0; $i <$count; $i++) 
    if ( isset($item[$i]) ) {
           if( in_array($item[$i], $skip_words) ) continue; //skip meaningless words
           $sql = "SELECT * FROM allquals WHERE Qualification LIKE '%$item[$i]%'";
           $rs = mysql_query($sql);
           while ( $row = mysql_fetch_array($rs, MYSQL_ASSOC) ) {
                  echo $row['Qualification'];
                  echo " ";
                  echo $row['QNo'];
                  echo "<br>";
           }
   }

Thanks Weirdan

Posted: Fri Dec 17, 2004 10:37 am
by rp
:D