Help needed - search problem
| From: | Fang Li | Date: | Thu, 15 Mar 2001 19:34:10 +0000 |
| Subject: | Help needed - search problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-44103@lists.php.net to get a copy of this message | ||
Hi, all:
Table News
__________________________
NewsID | Keywords | News
-------|-----------|------
1 |word1,word2| News1
-------|---------- |------
2 | word2 | News2
__________________________
I want to search this table based on the Keywords. the code is:
$split = explode(" ",$keywords);
$Num = 0;
for($index=0;$index<count($split);$index++){
$sql = "SELECT * FROM News WHERE Keywords LIKE '%$split[$index]%';
$result = mysql_query($sql) or die(mysql_error());
while($myrow = mysql_fetch_array($result)){
$Num = $Num +1;
$NewsID = $myrow["NewsID"];
$News = $myrow["News"];
echo $Num . ". " . $News . "<br>";
}//end while
}//end for
If the keywords inputted from user are: "word2, word1", it will reture News1
twice:
1. News1
2. News2
3. News1
I am trying to use array_diff, but I don't know how to do it, would anyone
please help me? Thanks a lot.
Fang