Gentilissimi vi posto il mio codex php
1) domanda..... vorrei porre un echo informativo..... nel caso che la ricerca effettuata non abbia prodotto nessun risultato.
ho provato a smanettare un pochetto il codice... ma non trovo soluzione...
se mi potete indirizzare un attimo ve ne sarei grato!
PHP:
<?php
$key = $_POST['key'];
class Search
{
#CONFIGURA
#Parametri ricerca
var $fulltext = "author,title";
var $table = "prova";
#parametri db
var $host = "";
var $password = "";
var $user = "";
var $db = "";
#
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.<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());
//
mysql_set_charset('utf8'); //
}
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();
$id=$row['author'];
$author=$row['title'];
while ($row = mysql_fetch_array($search->res))
{
echo "<div>";
echo "<br>";
echo "<font face=\"Arial\" size=\"2\">";
echo "<table width=\"640\" align=\"justify\" bgcolor=\"#FAFAD2\" cellpadding=\"3\" >";
echo "<tr>";
echo "<td>";
echo "<b>";
echo "Id:";
echo "</b>";
echo " ";
echo $row['author'];
echo " ";
echo $row['title'];
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
}
?>
1) domanda..... vorrei porre un echo informativo..... nel caso che la ricerca effettuata non abbia prodotto nessun risultato.
ho provato a smanettare un pochetto il codice... ma non trovo soluzione...
se mi potete indirizzare un attimo ve ne sarei grato!