l我设法创建了一个搜索引擎,可以在我的mysql数据库中检索我的结果。我可以查看此数据的元素。但是我希望以我在名为news.php的页面上显示的相同样式显示搜索结果。
的search.php:
if(isset($_POST['submit'])){
$search = $_POST['search'];
$search = "%$search%";
$articles = $db->prepare("SELECT * FROM articles WHERE headline LIKE :search");
$articles->bindParam(':search', $search);
$articles->execute(array(':search' => $search));
if($articles -> rowCount() > 0) {
while ($rows = $articles->fetch(PDO::FETCH_ASSOC)){
$headline = $rows['headline'];
echo "headline: $headline<br>";
}
} else{
echo "No Results";
}
}
News.php
$query = $handler->query('SELECT * FROM articles');
$results = $query->fetchAll(PDO::FETCH_ASSOC);
for ($i=0; $i < count($results); $i++) {
echo '<div class="col-md-4 col-xs-12 col-sm-12 height-news">';
echo '<p class="news-title">'.$results[$i]['headline'].'<br>'.'</p>';
echo '<img class="news-img" src="data:image/png;base64,'.base64_encode ( $results[$i]['logo'] ).'"/>';
echo '<p class="news-time">'.$results[$i]['date'].'<br>'.'</p>';
echo nl2br('<p class="news-body">'.$results[$i]['text'].'<br>'.'</p>') ;
echo '</div>';
}
答案 0 :(得分:0)
您需要发布到search.php文件。尝试这样的事情:
$('#yourSearhcButton").click(function(){
$.post("link/to/Search.php", { search: search });
});
阅读文档 - &gt; https://api.jquery.com/jquery.post/