title: How do I fix this PHP code?
body: <p>I have to create a live search on a website. I have to use PHP, but I have never studied it and I am pretty much a beginner in programming.</p>
  
  <p>I have an XML-file as a database and the aim is to get node values and display them as suggestions as a user types in something. The problem with this code is that it spits out all of the node values onto the web page. </p>
  
  <p>Here is the PHP code:</p>
  
  <pre><code>&lt;?php
  $xmlDoc = new DOMDocument();
  $xmlDoc-&gt;load("collection.xml");
  $books = $xmlDoc-&gt;getElementsByTagName("book");
  
  $q = $_GET["q"];
  
  if (strlen($q) &gt; 0) {
  $hint = "";
  
  foreach ($books as $book) {
      $name = $book-&gt;getElementsByTagName("name")-&gt;item(0)-&gt;nodeValue;
  
      echo "$name &lt;br/&gt;";
  }
  
  }
  
  if ($hint == "")
  {
  $response="no suggestion";
  }
  else
  {
  $response=$hint;
  }
  //output the response
  echo $response;
  ?&gt;
  </code></pre>
  
  <p>Here is the XML-file:</p>
  
  <pre><code>&lt;books&gt;
  
    &lt;book&gt;
      &lt;name&gt;Harry Potter&lt;/name&gt;
      &lt;quantity&gt; 50 &lt;/quantity&gt;
      &lt;price&gt;19.90&lt;/price&gt;
    &lt;/book&gt;
  
  
    &lt;book&gt;
      &lt;name&gt;Casino Royale&lt;/name&gt;
      &lt;quantity&gt; 50 &lt;/quantity&gt;
      &lt;price&gt;12.99&lt;/price&gt;
    &lt;/book&gt;
  
  
    &lt;book&gt;
      &lt;name&gt;The Great Gatsby&lt;/name&gt;
      &lt;quantity&gt; 40 &lt;/quantity&gt;
      &lt;price&gt;14.90&lt;/price&gt;
    &lt;/book&gt;
  
  &lt;/books&gt;
  </code></pre>
  
  <p>Can someone please help me fix this issue so that I can continue working on my project. Thank you in advance for your time and help! Aprreciate it a lot!</p>