Im travaillant sur un simple moteur de recherche, ce que je travaille bien, mais je veux changer cette ligne de code:moteur de recherche en utilisant l'erreur pdo
$query = "SELECT * FROM mobiles WHERE (`name` LIKE '%".$search."%') or (`type` LIKE '%".$search."%')";
à
$query = "SELECT * FROM mobiles WHERE (`name` LIKE '%:search%') or (`type` LIKE '%:search%')";
mais pour certains raison pour cela ne fonctionne pas
ici est le code complet php
<?php
require("../login/connect.php");
$search = $_GET['query'];
$query = "SELECT * FROM mobiles WHERE (`name` LIKE '%".$search."%') or (`type` LIKE '%".$search."%')";
$query_params = array(':search' => $_GET['query']);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$rows = $stmt->fetchAll();
$min_length = 3;
if(strlen($query) >= $min_length)
{
echo "<table border='0' width='600' align='center' cellpadding='1'>";
echo "<tr align='center' bgcolor='#03acfa' >
<td height='35px' width='200px'><b>Mobile Name</b></td>
<td><b>Mobile Type</b></td>
</tr>";
foreach($rows as $row):
{
echo "<tr align='center' bgcolor='#93dafb'>
<td height='25px'>". $row['name'] ."</td> <td>".$row['type']."</td>
</tr>" ;
}
endforeach;
}
Moteur de recherche? .. –