0
我在搜索控制器內使用此搜索功能將搜索結果發送到網頁。由於某種原因,它不起作用。我正在使用PDO,並且在php日誌中也看不到任何錯誤。 I'we花了很多時間試圖找出什麼是錯的,仍然好像它是一個失敗的事業php mysql搜索功能錯誤
public function search($search_string){
if (strlen($search_string) >= 1 && $search_string !== ' ') {
// Build Query
$sql = 'SELECT * FROM products WHERE name LIKE "%:search%" OR description LIKE "%:search%"';
$query = $this->db->prepare($sql);
$query->execute(array(':search' => $search_string));
$this->search=$query->fetchAll();
// Do Search
// Check If We Have Results
if (isset($query)) {
foreach($this->search as $key => $value) {
// Format Output Strings And Hightlight Matches
$display_function = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $value->name);
$display_name = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $value->name);
$display_url = 'http://hello.com/what'.urlencode($value->name).'&lang=en';
// Insert Name
$output = str_replace('nameString', $display_name, $html);
// Insert Function
$output = str_replace('functionString', $display_function, $output);
// Insert URL
$output = str_replace('urlString', $display_url, $output);
// Output
echo($output);
}
}else{
// Format No Results Output
$output = str_replace('urlString', 'javascript:void(0);', $html);
$output = str_replace('nameString', '<b>No Results Found.</b>', $output);
$output = str_replace('functionString', 'Sorry :(', $output);
// Output
echo($output);
}
}
}
http://stackoverflow.com/questions/15990857/reference-frequently-asked-questions-about-pdo#15990965 –
and also http://stackoverflow.com/questions/15990857/reference-frequently-asked-questions -about-pdo#15990858 –
我很確定它不是pdo搜索部分,因爲我使用了LIKE之前使用這種相同的方法..即時通訊猜測錯誤的PHP – user3117384