View Single Post
ישן 27-01-12, 20:47   # 15
Haimz
חבר וותיק
 
מיני פרופיל
תאריך הצטרפות: Sep 2010
הודעות: 1,221

Haimz לא מחובר  

משהו שרשמתי: (אין פה סידור של רלוונטיות)
PHP קוד:
<?php

    $connect 
mysql_connect("localhost","username","pass");
    
$db_select mysql_select_db("db"$connect);
    
    
$query "how to amazing hello man are you"// מילות חיפוש
    
$col "title"// העמודה
    
$density 2// אחד או שתיים - צפיפות המילים
    
    //---------------------------------------
    
    
$where = array();
    
$exploded explode(" "$query); // preg_split("/\s{1}/", $query);
    
$explode = array();
    
    if( 
$density == )
    {
        for( 
$x 0$x count($exploded); ++$x )
        {
            if( 
$x )
            {
                continue;
            }
            
            
$explode[$x] = trim($exploded[$x] . " " $exploded[$x 1]);
        }
    }
    else
    {
        
$explode explode(" "$query);
    }
    
    foreach( 
$explode as $q )
    {
        if( empty(
$q) )
            continue;
        
$where[] = $col" LIKE '%" .$q"%'";
    }
    
    
$whereSyntax implode(" OR "$where);
    
    if( !empty(
$whereSyntax) )
    {
        
$whereSyntax " WHERE " .$whereSyntax;
    }
    
    if( 
strtoupper(trim($whereSyntax)) == "WHERE" )
    {
        
$whereSyntax null;
    }
    
    
//---------------------------------------
    
    
$result mysql_query("SELECT " .$col" FROM tutorials" $whereSyntax);
    
    while( 
$row mysql_fetch_array($resultMYSQL_ASSOC) )
    {
        echo 
$row[$col] . "<br />\n";
    }

?>
אין פה סידור של רלוונטיות, יש לך אפשרות לשחק עם הצפיפות (המשתנה $density ) יכול להיות על אחד או שתיים, אם זה שתיים זה מחלק את המשפט מכל שתי מילים, אם זה על אחד זה מחלק אותו על כל מילה.

אבל כמו שאמרו לך פה, MATCH AGAINST זה הכי נוח לדעתי.
  Reply With Quote