Jump to content

First record is blank when I display xml on php page


cjackson111

Recommended Posts

Hello all.

 

I am using an API from jambase.com to display events on a php page. Everything works great, the xml file is read and the data is displayed on the page as it should. My only problem is that when the data is displayed there is always a blank area where the first record of data should go. Any ideas how to get rid of this?

 

http://www.wddclients.com/mag33/events_search.php (artist search field not enabled yet)

 

Hopefully this is something pretty minor but if anyone wants to see specific code I can supply that.

 

Thanks so much for all help!

Sure, here is my php code which reads and displays the xml data.

 

<?php
//if ( isset( $_POST['zip'] ) )  

//echo $zip;


    if( ! $xml = @simplexml_load_file("http://api.jambase.com/search?zip=$zip&radius=$radius&n=75&apikey=[my api key]") ) 
    { 
        echo 'unable to load XML file';
    } 
    else 
    { 
        //echo 'XML file loaded successfully';
	echo '<table width="590" cellpadding="6" cellspacing="0">';
	foreach( $xml as $event ) //foreach( $xml as $user ) 
        { 	
	echo '<tr valign="top" bgcolor="#000000">';
	echo '<td width="300" background="image/bg_results2.gif"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>';
	echo ''.$event->artists->artist->artist_name.''; //artist_name
	echo '</strong><br>   '.$event->event_date.'<br>   Live at '.$event->venue->venue_name.'<br>   '.$event->venue->venue_city.', '.$event->venue->venue_state.' '.$event->venue->venue_zip.'';
	echo '</font></td>';
	echo '<td width="290" align="right" background="image/bg_results2.gif">     <a href="'.$event->event_url.'" target="_blank"><img src="image/detail_button.gif" alt="Event Details" vspace="5" width="71" height="25" border="0"></a>'; //event link
	//echo '     ';

	if (!$event->ticket_url){
	}
	else{
	echo '     <a href="'.$event->ticket_url.'" target="_blank"><img src="image/ticket_button.gif" alt="Get Tickets" vspace="5" width="71" height="25" border="0"></a>'; //ticket link
	}

	echo '</td>';
	echo '</tr>';
        } 
	echo '</table>';
    } 

?>

I would do it like this.  There is just one line added.  "continue" means "jump to the next item in the loop", more or less.

 

		foreach( $xml as $event ) //foreach( $xml as $user ) 
        {
		if (!$event->event_date) continue; # New line - skip event if it doesn't have a date

	echo '<tr valign="top" bgcolor="#000000">';
	echo '<td width="300" background="image/bg_results2.gif"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>';
	echo ''.$event->artists->artist->artist_name.''; //artist_name
	echo '</strong><br>   '.$event->event_date.'<br>   Live at '.$event->venue->venue_name.'<br>   '.$event->venue->venue_city.', '.$event->venue->venue_state.' '.$event->venue->venue_zip.'';
	echo '</font></td>';
	echo '<td width="290" align="right" background="image/bg_results2.gif">     <a href="'.$event->event_url.'" target="_blank"><img src="image/detail_button.gif" alt="Event Details" vspace="5" width="71" height="25" border="0"></a>'; //event link
	//echo '     ';

	if (!$event->ticket_url){
	}
	else{
	echo '     <a href="'.$event->ticket_url.'" target="_blank"><img src="image/ticket_button.gif" alt="Get Tickets" vspace="5" width="71" height="25" border="0"></a>'; //ticket link
	}

	echo '</td>';
	echo '</tr>';
        } 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.