Salve a tutti,
una cosa molto semplice: siccome ancora non ho dimestichezza con la versione 5 di PHP, avevo scaricato uno script per un motore di ricerca interno, solo che non riesco a far passare la variabili POST in key. Qualcuno mi può gentilmente aiutare?
pagina 1:
pagina 2:
una cosa molto semplice: siccome ancora non ho dimestichezza con la versione 5 di PHP, avevo scaricato uno script per un motore di ricerca interno, solo che non riesco a far passare la variabili POST in key. Qualcuno mi può gentilmente aiutare?
pagina 1:
HTML:
<form name='ricerca' method='post' action='ricerca.php'>
<input name="key" type="text" id="mostraricerca" placeholder="Parola chiave..." size="20" maxlength="20" ><input type="submit" name="ricerca" value="Cerca"></form>
pagina 2:
PHP:
$key=$_POST['mostraricerca'];
class Search
{
#CONFIGURA
#Parametri ricerca
var $fulltext = "titolo";
var $table = "database";
#parametri db
var $host = "localhost";
var $password = "";
var $user = "root";
var $db = "database";
#metodo score -> p in percentuale, f in frazione
var $pf = "f";
#FINE CONFIGURAZIONE
#NON EDITARE OLTRE QUESTA LINEA
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.<br>MySql risponde: " . mysql_error() . "<br>Il codice errore é:" . mysql_errno());
@mysql_select_db($this->db, $this->conn) or die ("Impossibile connettersi al database $this->db.<br>MySql risponde: " . mysql_error() . "<br>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['titolo'] . " score: " . $search->CalcScore($row['tot']);
}