Echo message via PHP if XML element doesn't exist

dsadsfa

New Member
After some substantial research on this topic, I have unfortunately not found an answer. I would imagine that this is an exceptionally simple question for a lot of people here.I'm connected to Last.fm's XML database through their API (Using PHP). On entering an artist that exists, or a blank field, I can echo the correct information with no issues. I cannot however echo anything if the user types in an artist that doesn't exist.My question is this; how can I echo whatever message I want if that XML element does not exist? My line of thought was as follows:\[code\] foreach ($uk_events as $event){$venue_city = (string) $event->venue->location->city;$image = (string) $event->image[2];$uk_street = (string) $event->venue->location->street;$uk_postcode = (string) $event->venue->location->postalcode;$startdate = (string) $event->startDate;$starttime = (string) $event->startTime;$uk_venues = (string) $event->venue->name; $uk_names = (string) $event->artists->artist;$website = (string) $event->website; if (empty($uk_names)){ echo "<p class='sorry'>Sorry, but it doesn't look like this artist exists. Either they're exceptionally obscure or they're from another realm. Try again, or have a look at the below suggestions.</p>"; }\[/code\]After some trial and error the best that I have gotten is for the above to be echoed, but it's echoed regardless of what's searched for. I need the above to appear only if the artist doesn't exist within the XML database.Much appreciated for anyone who can give me an idea as to how to progress on this one.Thank you.
 
Back
Top