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>";

People are also looking for solutions to the problem: sql - JOIN not working with PHP + ODBC + Microsoft Access

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.