2012-07-02 6 views
-2

PHP에서 관련 콘텐츠를 가져 오는 좋은 방법은 무엇입니까? 내 키워드 최대 결과가 관련 할무엇이 좋은 방법인가 관련 콘텐츠

$keywords = 'Most Perfectly Timed Videos EVER'; 
$rel = mysql_query("select * from media where title LIKE '%$keywords%'")or 
die(mysql_error()); 

: 내가 제목 LIKE '% 1 $ 키워드 %가'는 same.my 방법은 같은 간단 반환 곳에서 사용하는 경우 내가, $ 키워드를 가지고있다. 감사합니다. .

+0

발생한 문제는 무엇인가? – mithunsatheesh

+0

http://dev.mysql.com/doc/refman/5.6/en/fulltext-search.html을 살펴보십시오. –

답변

1
$query = "SELECT * FROM media WHERE "; 
$keywords = 'Most Perfectly Timed Videos EVER'; 
$keywords = explode(" ", $keywords); 
$where = ""; 
foreach($keywords as $k => $v) 
{ 
    $where .= "title LIKE '%".$v."%' AND "; 
} 
$where = substr($where, 0, -5); //deleting the last "AND" 

$query .= $where; 
$rel = mysql_query($query) or die(mysql_error()); 

또는, 당신은 "AND"더 나은 결과를 위해 "OR"대신 사용할 수있는 경우 :

foreach($keywords as $k => $v) 
{ 
    $where .= "title LIKE '%".$v."%' OR "; 
} 
$where = substr($where, 0, -4); 
관련 문제