我的php / MySQL搜索查询没有返回错误,也没有显示MySQL表的结果。例如,我有6行,每列包含3-5个单词(以逗号分隔)。如果用户键入与特定列的单词匹配的某个单词,则它应该仅拉取并显示该行/那些行。有人能指出我正确的方向,这是我的代码(数据库连接正常工作)
include('database.php');
echo "<div class='grid_4'>
<form action='' method='POST'>
<input type='text' name='search' maxlength='60' size='20px' placeholder='Under Construction...'/>
<input type='submit' name='ssearch' value='Search' id='favb'>
</form>
</div>";
if(isset($_POST['ssearch']) && $_POST['ssearch'] != "")
{
$SB=$_POST['ssearch'];
$search=$db->prepare("SELECT body FROM thread WHERE body LIKE ?");
$search->execute(array('%'.$SB.'%'));
$search->setFetchMode(PDO::FETCH_ASSOC);
$sR="";
while($row=$search->fetch())
{
$title=$row['title'];
$thread_id=$row['thread_id'];
$preview=$row['preview'];
$sR.='<div class="grid_3" id="previewmargin">
<a href="view_thread.php?id='.$thread_id.'" id="tt">'.$preview.'</a></div>';}
}
echo $sR;
答案 0 :(得分:0)
在您运行搜索的行,如果您从以下地址更改:
$search->execute(array('%'.$SB.'%'));
为:
$search->execute(array("'%" . $SB . "%'"));