title: PHP Ajax to Display Clicked Result
body: <p>I have the codes to search autocomplete from MySQL and the match query can be clicked and direct me to a new page. How can i have the result of the clicked queries to be displayed in the new page w/out using any URL from database because I need to avoid using lots of HTML files. Thank you.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;p id="searchresults"&gt;
  &lt;?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-&gt;real_escape_string($_POST['queryString']);
     
     // Is the string length greater than 0?
     if(strlen($queryString) &gt;0) {
      $query = $db-&gt;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 -&gt;fetch_object()) {
        if($result-&gt;bookTitle != $bookTitle) { // check if the category changed
         echo '&lt;span class="category"&gt;'.$result-&gt;bookTitle.'&lt;/span&gt;';
         $bookTitle = $result-&gt;bookTitle;
        }
               echo '&lt;a href="'.$result-&gt;url.'"&gt;';
               echo '&lt;img src="search_images/'.$result-&gt;bookimage.'" alt="" /&gt;';
               
               $bookTitle = $result-&gt;bookTitle;
               if(strlen($bookTitle) &gt; 35) { 
                $bookTitle = substr($bookTitle, 0, 35) . "...";
               }             
               echo '&lt;span class="searchheading"&gt;'.$bookTitle.'&lt;/span&gt;';
               
               $author = $result-&gt;author;
               if(strlen($author) &gt; 80) { 
                $author = substr($author, 0, 80) . "...";
               }
               
               echo '&lt;span&gt;'.$author.'&lt;/span&gt;&lt;/a&gt;';
              }
              echo '&lt;span class="seperator"&gt;&lt;a href="http://www.marcofolio.net/sitemap.html" title="Sitemap"&gt;Nothing interesting here? Try the sitemap.&lt;/a&gt;&lt;/span&gt;&lt;br class="break" /&gt;';
      } 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!';
    }
   }
  ?&gt;
  &lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>