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?
$query = 'tap';
//connect to the database
$db = new mysqli('localhost', $username, $password, $database );
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->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->query($sqlQuery)){
die('There was an error running the query [' . $db->error . ']');
}
Header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<totalResults>Total results: ' . $result->num_rows . '</totalResults>';
//close the database connection
$db->close();