ciao vorrei che la ricerca delle parole chiavi sia piu precisa soprattutto se il campo del tatabase contiene piu paroloe dentro il campo parolechiavi , in pratica se inserisco piazza venezia mi trova solo quella e non tutti i campi dove cè anche piazza ...
Codice PHP:
<?php
session_start();
$key = $_POST["comments"];
class Search
{
#CONFIGURA
#Parametri ricerca
var $fulltext = "proprietario,nomefoto,parolechiavi,emailproprietario";
var $table = "fotopubbliche";
#parametri db
var $host = "62.";
var $password = "363";
var $user = "Sq";
var $db = "reyreyer";
#metodo score -> p in percentuale, f in frazione
var $pf = "f";
var $key;
var $conn;
var $res;
var $total;
function Search($key)
{
$this->key = $key;
}
function DbConnectAndSelect()
{
$this->conn = @mysql_connect($this->host, $this->user, $this->password) or die ("Impossibile stabilire una connessione con il server.
MySql risponde: " . mysql_error() . "
Il codice errore é:" . mysql_errno());
@mysql_select_db($this->db, $this->conn) or die ("Impossibile connettersi al database $this->db.
MySql risponde: " . mysql_error() . "
Il codice errore é:" . mysql_errno());
}
function GetResource()
{
$this->DbConnectAndSelect();
$sql = "SELECT *, MATCH($this->fulltext) AGAINST('$this->key' IN BOOLEAN MODE) AS tot FROM $this->table WHERE MATCH($this->fulltext) AGAINST('$this->key' IN BOOLEAN MODE) ORDER BY tot DESC";
$this->res = mysql_query($sql, $this->conn);
}
function CalcScore($tot)
{
switch($this->pf)
{
case "f":
$key_array = explode(" ", $this->key);
$this->total = count($key_array);
return $tot . " / " . $this->total;
break;
case "p":
$key_array = explode(" ", $this->key);
$this->total = count($key_array);
$output = intval($tot / $this->total * 100) . "%";
return $output;
break;
default:
$key_array = explode(" ", $this->key);
$this->total = count($key_array);
return $tot . " / " . $this->total;
}
}
}
$search = new Search($key);
$search->GetResource();
while ($row = mysql_fetch_array($search->res))
{
echo $row['nomefoto'];
}
?>
grazie chissa