Advertisement
Guest User

Untitled

a guest
Apr 11th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2. require_once('/tmp/sphinx-2.2.10-release/api/sphinxapi.php');
  3.  
  4. $searchterm = htmlspecialchars($_GET['suche']);
  5. //Sphinx-Search    
  6.  
  7. $cl = new SphinxClient();
  8. $cl->SetServer("localhost", 9312);
  9. $cl->SetMatchMode(SPH_MATCH_ANY);
  10.  
  11. $result = $cl->Query($searchterm, 'music');
  12.  
  13.     if ( ! empty($result["matches"])) {
  14.         foreach ( $result["matches"] as $key => $value)
  15.         {
  16.             $servername = "localhost";
  17.             $username = "root";
  18.             $pass = "Musik4live!";
  19.             $dbname = "sphinx-music";
  20.             $conn = new mysqli ($servername, $username, $pass, $dbname);
  21.             if ($conn->connect_error)
  22.             {
  23.                 die ("Connection failed: " . $conn->connect_error);    
  24.             }
  25.             $sql = "SELECT music_id, title, interpret, year FROM music WHERE music_id = $key";
  26.             $result2 = $conn->query($sql);
  27.    
  28.             if($result2->num_rows > 0)
  29.             {
  30.             while ($row = $result2->fetch_assoc())
  31.             {
  32.             echo "<br>id: ". $row["music_id"]. " - Title: " .$row["title"] . " - Interpret: ". $row['interpret']. "<br>";
  33.             }
  34.             }
  35.             else
  36.             {  
  37.             echo " 0 results";
  38.             }
  39.             $conn->close();
  40.  
  41.  
  42.         }
  43.        
  44.        
  45.     }
  46.  
  47.             exit;
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement