0
我有从MySQL搜索自动完成的代码,匹配查询可以点击并指引我到一个新的页面。我怎样才能将点击查询的结果显示在新页面中,无需使用数据库中的任何URL,因为我需要避免使用大量的HTML文件。谢谢。PHP Ajax显示点击结果
<p id="searchresults">
<?php
\t // PHP5 Implementation - uses MySQLi.
\t // mysqli('localhost', 'yourUserbookTitle', 'yourPassword', 'yourDatabase');
\t $db = new mysqli('localhost', 'root', '', 'book');
\t
\t if(!$db) {
\t \t // Show error if we cannot connect.
\t \t echo 'ERROR: Could not connect to the database.';
\t } else {
\t \t // Is there a posted query string?
\t \t if(isset($_POST['queryString'])) {
\t \t \t $queryString = $db->real_escape_string($_POST['queryString']);
\t \t \t
\t \t \t // Is the string length greater than 0?
\t \t \t if(strlen($queryString) >0) {
\t \t \t \t $query = $db->query("SELECT * FROM bookinfo WHERE bookTitle LIKE '%" . $queryString . "%'");
\t \t \t \t
\t \t \t \t if($query) {
\t \t \t \t \t // While there are results loop through them - fetching an Object.
\t \t \t \t \t
\t \t \t \t \t // Store the category id
\t \t \t \t \t $bookTitle = 0;
\t \t \t \t \t while ($result = $query ->fetch_object()) {
\t \t \t \t \t \t if($result->bookTitle != $bookTitle) { // check if the category changed
\t \t \t \t \t \t \t echo '<span class="category">'.$result->bookTitle.'</span>';
\t \t \t \t \t \t \t $bookTitle = $result->bookTitle;
\t \t \t \t \t \t }
\t \t \t \t echo '<a href="'.$result->url.'">';
\t \t \t \t echo '<img src="search_images/'.$result->bookimage.'" alt="" />';
\t \t \t \t
\t \t \t \t $bookTitle = $result->bookTitle;
\t \t \t \t if(strlen($bookTitle) > 35) {
\t \t \t \t \t $bookTitle = substr($bookTitle, 0, 35) . "...";
\t \t \t \t } \t \t \t \t
\t \t \t \t echo '<span class="searchheading">'.$bookTitle.'</span>';
\t \t \t \t
\t \t \t \t $author = $result->author;
\t \t \t \t if(strlen($author) > 80) {
\t \t \t \t \t $author = substr($author, 0, 80) . "...";
\t \t \t \t }
\t \t \t \t
\t \t \t \t echo '<span>'.$author.'</span></a>';
\t \t \t }
\t \t \t echo '<span class="seperator"><a href="http://www.marcofolio.net/sitemap.html" title="Sitemap">Nothing interesting here? Try the sitemap.</a></span><br class="break" />';
\t \t \t \t } else {
\t \t \t \t \t echo 'ERROR: There was a problem with the query.';
\t \t \t \t }
\t \t \t } else {
\t \t \t \t // Dont do anything.
\t \t \t } // There is a queryString.
\t \t } else {
\t \t \t echo 'There should be no direct access to this script!';
\t \t }
\t }
?>
</p>
请显示你的代码。 –
请帮忙。谢谢 –