My question is what can I do if someone searches for php script for search?

I would want to use OR in my SQL statment. The problem is how do I write the
query so that it will detect the number of words sent then put enough ORs
and LIKE '%$search[1]% in?

Thanks.


Here is the script.

<?
include "includes/required.php";
$query = "
SELECT count(article_keyword.weight) as score, article_keyword.aid,
article_data.name, article_data.time, article_data.description
FROM article_keyword,article_data
WHERE article_keyword.aid = article_keyword.aid AND article_keyword.keyword
LIKE '%$search%'
GROUP BY article_keyword.aid
ORDER BY score DESC
";
$result = mysql_query($query) or die("Query failed: $query<br>" .
mysql_error());
$num_results = mysql_num_rows($result);
if($num_results == 0){
  echo "Your search returned no results. Try other keyword(s).";
 exit;
} elseif($num_results > 0){
  for ($i=0; $i < $num_results; $i++)
    {
   $row = mysql_fetch_array($result);
    echo '<tr><td>';
  do_hr();
  echo '<a href="full_article.php?aid='.$row['aid'].'">';
  do_h($row['name'].' - '.date('jS-M-Y',$row['time']), 3, 'n');
  echo '</a>';
    echo '</td></tr><tr><td>'.$row['description']."\n";
   echo '</td></tr>';
}
 }
?>

"Jj Harrison" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> To add search functionality I decieded this was the best table structure I
> could come up with for a  keywords table.
>
> Here it is:
>
> CREATE TABLE article_keyword (
>   aid int(11) unsigned NOT NULL default '0',
>   keyword char(50) NOT NULL default '',
>   weight tinyint(2) unsigned NOT NULL default '0',
>   PRIMARY KEY  (aid),
>   KEY keyword (keyword),
>   KEY aid (aid),
>   KEY weight (weight)
> ) TYPE=MyISAM;
>
> Using that structure could I get a decent search?
>
> I would probably add up the weight for each keyword(Where it is searched
> for). Then sort it by the most 'relevent' then I could use a join to get
the
> title, time etc of the article and return the results.
>
> What I am asking is that if this is a good table structure for something
> like this(N00B alert!). If not could you please give me a better one?
>
>
> --
> JJ Harrison
> [EMAIL PROTECTED]
> www.tececo.com
>
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to