php - if no results from xml api call then
255
I'm running a basic api call and it returns a xml file..i go through the data and set them equal to variables and then echo..all works fine unless there are no results and then it is just blank. How can I add an if statement to check if the api call returned any results?
if($url_headers[0] == 'HTTP/1.1 200 OK' && (!empty($searchCode))) {
$xml = simplexml_load_file($searchCode);
foreach ($xml->result->result as $result):
$cake=$result->{'cakename'};
$icecream=$result->{'icecreamname'};
echo "<ul class='cakes' >";
echo "<li>$cake and $icecream</li>";
echo "</ul>";
Answer
Solution:
You are searching for the function
. Use it like this:
Of course you can elaborate on this the have a more detailed error message.