<?php
require("connessione.php");

if((!$stringa) || ($stringa==""))
{
echo "<font face=\"arial\" size=\"2\">E' necessario specificare la/le parola/parole da cercare
<a href=\"java script:history.back()\">indietro</a></font>";
exit();
}
if($ordine=="crescente") { $ord="ASC"; }
elseif($ordine=="decrescente") { $ord="DESC"; }
$cn=mysql_connect($host,$uid,$pw);
mysql_select_db($db,$cn);
$sql="SELECT*FROM".$tabella."WHERE ";
if($criterio=="esatta")
{
$sql="testo LIKE '%$stringa%' ORDER BY id" .$ord;
}
elseif($criterio=="almeno")
{
$lista_parole=explode(" ",$stringa);
for($i=0;$i<=count($lista_parole);$i++)
{
$str="testo LIKE '%$lista_parole[$i]%' OR ";
}
$str=substr($str,0,(strlen($str)-3));
$sql=$str." ORDER BY id".$ord;
}
elseif($criterio=="tutte")
{
$lista_parole=explode(" ",$stringa);
for($i=0;$i<=count($lista_parole);$i++)
{
$str="testo LIKE '%$lista_parole[$i]%' AND ";
}
$str=substr($str,0,(strlen($str)-4));
$sql=$str." ORDER BY id".$ord;
}
$query=mysql_db_query($db,$sql);
$num=mysql_num_rows($query);
?>
<html>
<head>
<title>Esempio di motore di ricerca</title>
</head>
<body>
<center>
<font face="arial" color="red">Risultati della ricerca</font>


<?php
if($num<1)
{
echo "<font face=\"arial\" size=\"2\">Nessun risultato trovato
<a href=\"java script:history.back()\">indietro</a></font>";
}
elseif($num>=1)
{
echo "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\" bgcolor=\"silver\" bordercolor=\"red\"><tr valign=\"top\"><td><font face=\"arial\" size=\"2\">[b]Data inserimento[b]</td><td><font face=\"arial\" size=\"2\">Testo</td></tr>";
while($riga=mysql_fetch_array($query))
{
echo "<tr><td><font face=\"arial\" size=\"2\">".$riga[data]."</td><td><font face=\"arial\" size=\"2\">".nl2br($riga[testo])."</td></tr>";
}
echo "</table>
<font face=\"arial\" size=\"2\"><a href=\"java script:history.back()\">indietro</a><font face=\"arial\" size=\"2\">";
}
echo "

<font face=\"arial\" size=\"2\">Query SQL generata:
".$sql."</font>";
mysql_close($cn);
?>
</center>
</body>
</html>

ho modificato delle cose tipo punti (str.= ?? ho messo str=... Poi for($i=0;$i<=count();$i++)...)
e degli apici... fammi sapere