IM在一個簡單的搜索引擎的工作,我有什麼工作正常,但我想改變這行代碼:搜索引擎
$query = "SELECT * FROM mobiles WHERE (`name` LIKE '%".$search."%') or (`type` LIKE '%".$search."%')";
到
$query = "SELECT * FROM mobiles WHERE (`name` LIKE '%:search%') or (`type` LIKE '%:search%')";
但對於一些原因這是行不通的
以下是完整的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;
}
搜索引擎?.. –