1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <html>
<head>
<title>Search Results</title>
</head>
<body>
<h1>Search Results</h1>
<?php
// Enlever les espaces avant et après
$searchterm = trim($_POST['searchterm']);
if (!$searchterm) {
// echo "Vous n'avez pas saisi les détails de la recherche";
echo 'You have not entered search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc()){
$searchterm = addslashes($searchterm);
}
@ $db = new mysqli('localhost', 'root', '', 'bdd');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = " SELECT *
FROM table
WHERE MATCH(code,titre) AGAINST('%".$searchterm."%')
ORDER BY MATCH(code,titre) AGAINST('%".$searchterm."%') DESC";
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<p>Number of results found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". Code: ";
echo htmlspecialchars(stripslashes($row['code']));
echo "</strong><br />Titre: ";
echo stripslashes($row['titre']);
echo "</p>";
}
$result->free();
$db->close();
?>
</body>
</html> |
Partager