title: Using MYSQLI in php to search data and return results as XML
body: <p>I'm tying to make a script which will return all the columns in my database for each row if one of the columns matches a keyword. E.g. in the example below all rows which have a match for the word tap are returned. I then want to render the results out as xml. The code below seems to work and totalResults shows the number of matches found. How do I loop over each results and render out all matched data by the SQL query?</p>
  
  <pre><code>   $query = 'tap';
  
      //connect to the database
  $db = new mysqli('localhost', $username, $password, $database );
  if($db-&gt;connect_errno &gt; 0){
      die('Unable to connect to database [' . $db-&gt;connect_error . ']');
  }
  
  //query the database    
  $sqlQuery = "select * from skus
  where
  `id` like '%$query%' OR
  `name` like '%$query%' OR
  `description` like '%$query%' OR
  `ean` like '%$query%' OR
  `price` like '%$query%' OR
  `wasPrice` like '%$query%' OR
  `deliveryCost` like '%$query%' OR
  `deliveryTime` like '%$query%' OR
  `stockAvailability` like '%$query%' OR
  `skuAvailableInStore` like '%$query%' OR
  `skuAvailableOnline` like '%$query%' OR
  `channel` like '%$query%' OR
  `manufacturersPartNumber` like '%$query%' OR
  `specificationsModelNumber` like '%$query%' OR
  `featuresBrand` like '%$query%' OR
  `imageUrl` like '%$query%' OR
  `thumbnailUrl` like '%$query%' OR
  `features` like '%$query%' OR
  `url` like '%$query%' OR
  `productHierarchy` like '%$query%'";
  if(!$result = $db-&gt;query($sqlQuery)){
      die('There was an error running the query [' . $db-&gt;error . ']');
  }
  
      Header('Content-type: text/xml');
  
  echo '&lt;?xml version="1.0" encoding="utf-8"?&gt;';
  
  echo '&lt;totalResults&gt;Total results: ' . $result-&gt;num_rows . '&lt;/totalResults&gt;';
  
  //close the database connection
  $db-&gt;close();
  </code></pre>