cjackson111 Posted March 3, 2011 Share Posted March 3, 2011 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! Quote Link to comment Share on other sites More sharing options...
btherl Posted March 4, 2011 Share Posted March 4, 2011 Please show the specific code. Quote Link to comment Share on other sites More sharing options...
cjackson111 Posted March 4, 2011 Author Share Posted March 4, 2011 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>'; } ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted March 4, 2011 Share Posted March 4, 2011 Maybe your parser is giving you a blank entry at the start? You could check it and ignore any blank entries. Or it may be parsing something at the start which is not an event. Quote Link to comment Share on other sites More sharing options...
cjackson111 Posted March 4, 2011 Author Share Posted March 4, 2011 How would I set it to ignore any blank entries? I am fairly new to this. Thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted March 4, 2011 Share Posted March 4, 2011 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>'; } Quote Link to comment Share on other sites More sharing options...
cjackson111 Posted March 4, 2011 Author Share Posted March 4, 2011 Ahhhhh! Works like a charm now. You are awesome! Thank you very much!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.