繁体   English   中英

PHP Ajax显示点击结果

[英]PHP Ajax to Display Clicked Result

我有从MySQL搜索自动完成功能的代码,可以单击匹配查询并将我定向到新页面。 如何使用数据库中的任何URL将单击查询的结果显示在新页面中,而无需使用URL,因为我需要避免使用大量HTML文件。 谢谢。

 <p id="searchresults"> <?php // PHP5 Implementation - uses MySQLi. // mysqli('localhost', 'yourUserbookTitle', 'yourPassword', 'yourDatabase'); $db = new mysqli('localhost', 'root', '', 'book'); if(!$db) { // Show error if we cannot connect. echo 'ERROR: Could not connect to the database.'; } else { // Is there a posted query string? if(isset($_POST['queryString'])) { $queryString = $db->real_escape_string($_POST['queryString']); // Is the string length greater than 0? if(strlen($queryString) >0) { $query = $db->query("SELECT * FROM bookinfo WHERE bookTitle LIKE '%" . $queryString . "%'"); if($query) { // While there are results loop through them - fetching an Object. // Store the category id $bookTitle = 0; while ($result = $query ->fetch_object()) { if($result->bookTitle != $bookTitle) { // check if the category changed echo '<span class="category">'.$result->bookTitle.'</span>'; $bookTitle = $result->bookTitle; } echo '<a href="'.$result->url.'">'; echo '<img src="search_images/'.$result->bookimage.'" alt="" />'; $bookTitle = $result->bookTitle; if(strlen($bookTitle) > 35) { $bookTitle = substr($bookTitle, 0, 35) . "..."; } echo '<span class="searchheading">'.$bookTitle.'</span>'; $author = $result->author; if(strlen($author) > 80) { $author = substr($author, 0, 80) . "..."; } echo '<span>'.$author.'</span></a>'; } 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" />'; } else { echo 'ERROR: There was a problem with the query.'; } } else { // Dont do anything. } // There is a queryString. } else { echo 'There should be no direct access to this script!'; } } ?> </p> 

我不知道我的问题是否正确,但是如果您需要显示一个包含所选图书数据/评论/评论的新页面,我会添加:

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值从数据库检索数据并显示它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM