You are here:  » Check if null


Check if null

Submitted by GeXus on Sat, 2007-03-17 21:32 in

How would you go about determining if the results are null, and if they are null, to provide a differnet xml url?

Submitted by support on Sun, 2007-03-18 08:48

Hi,

The most straight forward way is to set another global variable for example $gotRecords and set this to TRUE in your record handler. You can then check it after the parse to see if any records existed, and try again with another URL if not. For example:

<?php
  
// create a global variable to indicate results and set to FALSE
  
$gotRecords FALSE;
  function 
myRecordHandler($record)
  {
    
// set $gotRecords to TRUE because we know we have records here
    
global $gotRecords;
    
$gotRecords TRUE;
  }
  
// parse as usual
  
MagicParser_parse("file.xml","myRecordHandler");
  
// after parsing, check if $gotRecords is still FALSE
  
if (!$gotRecords)
  {
    
// try and parse your backup URL
    
MagicParser_parse("file2.xml","myRecordHandler");
  }
?>

You can of course do the same test again after parsing the second file, and if it's still FALSE display a message for example...

Cheers,
David.