You are here:  » Autonumber rows on XML output


Autonumber rows on XML output

Submitted by rcasey on Mon, 2016-03-28 17:25 in

Hello,

I'm looking to simply autonumber the rows of the data we're parsing from an XML feed. Currently, we're getting:

Result A 555
Result B 444
Result C 435

I'd like:

1 Result A 555
2 Result B 444
3 Result C 435

Any ideas?

Thank you.

Submitted by support on Tue, 2016-03-29 08:55

Hi,

Create a counter variable outside of your myRecordHandler() function, and then within the function declare the counter variable as global, increment by 1 and include within your output as required; for example:

<?php
  $counter 
0;
  function 
myRecordHandler($record)
  {
    global 
$counter;
    
$counter++;
    print 
$counter." ".$record["FIELD1"]." ".$record["FIELD2"]."\n";
  }
?>

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by rcasey on Wed, 2016-03-30 17:34

Thank you, that's exactly what I was looking for!