Search query - how do I ...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rp
Forum Newbie
Posts: 21
Joined: Wed Nov 24, 2004 5:49 am

Search query - how do I ...

Post 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:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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>";
           }
   }
rp
Forum Newbie
Posts: 21
Joined: Wed Nov 24, 2004 5:49 am

Thanks Weirdan

Post by rp »

:D
Post Reply