Salve
Stavo cercando uno script in ASP su db Mysql (no access) per creare un motore di ricerca interno al sito.
ho trovato un script scritto in Php e non riesco a convertirlo in ASP.
------------- CODICE PHP CHE VOGLIO CONVERTIRE IN ASP
<form method="post" action="cerca.php">
<input type="text" name="testo">
<input type="submit" value="Cerca">
</form>
<?
$cn = mysql_connect("localhost", "mia_username", "mia_password");
@mysql_select_db("mio_database", $cn);
$testo = htmlspecialchars(addslashes($_POST["testo"]));
?>
<html><head><title>Risultati della ricerca</title></head><body>
Risultati della ricerca:
<?
if (isset($testo) == false || $testo == "")
{
echo "nessun risultato!";
}
else
{
echo $testo;
}
?>
</p>
<?
if (isset($testo) == false || $testo == "")
{
?>
Specificare un criterio di ricerca.</p>
<?
}
else
{
$arr_txt = explode(" ", $testo);
$sql = "SELECT * FROM articoli WHERE ";
for ($i=0; $i<count($arr_txt); $i++)
{
if ($i > 0)
{
$sql .= " AND ";
}
$sql .= "(titolo LIKE '%" . $arr_txt[$i] . "%' OR descrizione LIKE '%" . $arr_txt[$i] . "%')";
}
$sql .= " AND cat_id = art_categoria ORDER BY art_timestamp DESC";
$query = mysql_query($sql, $cn);
$quanti = mysql_num_rows($query);
if ($quanti == 0)
{
?>
Nessun risultato!</p>
<?
}
else
{
for($x=0; $x<$quanti; $x++)
{
$rs = mysql_fetch_row($query);
$id = $rs[0];
$titolo = $rs[1];
?>
<?echo $titolo?></p>
<?
}
}
}
?></body></html>
------------------ FINE CODICE PHP DA CONVERTIRE IN ASP
----------------- INIZIO CONVERSIONE DOVE CERCO AIUTO
<form method="post" action="cerca.ASP">
<input type="text" name="testo">
<input type="submit" value="Cerca">
</form>
<%'TRALASCIO LA STRINGA DI CONNESSIONE ED I CONTROLLI CARATTERI SPECIALI SUL TESTO%>
<%testo = request.form("testo")%>
<%
if testo = "" then
response.write ("Devi inserire del testo nel campo di ricerca")
else
response.write ("testo ricercato : " &testo)
arr_txt = split (testo, ",")
SQL="SELECT * FROM nomeTabella where"
for i =0 to i < arr_txt.lenght i++
'eseguo
if i > 0 then
SQLcerca = SQLcerca & " and"
response.write(SQLcerca)
else
SQLcerca = SQLcerca & "NomeCampo = '"& arr_txt(i) &"' "
response.write(SQLcerca)
end if
next
%>
<%
end if
%>
............... partirei da qua il resto per me è molto complicato
Grazie in anticipo