2017-03-24 9 views
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>

+3

してくださいあなたのコードを表示します。 –

+0

助けてください。ありがとうございました –

答えて

0

私は右のあなたの問題を取得する場合、私は知りませんが、あなたが選択した書籍データ/レビュー/コメントを使用して新しいページを表示する必要が場合、私は追加します。

echo '<span>'.$author.'</span></a>'; /* after this line */ 
echo '<span>Read more > <a href="newpage.php?id='.$bookID.'">click here</a></span>'; /* where $bookID id the ID column in your DB */ 

その後、新しいページに、$ bookID値に応じてDBからデータを取得し、それを表示...

関連する問題