tags:

views:

73

answers:

1

Hi

I have my simpleXML script creating new element's in a xml file but I need the attribute to be a auto incremented id

for example

<gig id="1">
        <date>December 19th</date>
        <venue>The Zanzibar</venue>
        <area>Liverpool</area>
        <telephone>Ticketline.co.uk</telephone>
        <price>£6</price>
        <time>Time TBA</time>   
    </gig>  

Is correct but when I create a new elemenet the id has to be written in by myself.

My code is as followed

 $line1 = $sxe->addChild('gig');
    $line1->addChild('id', HERE HERE HERE!!!!!!);
    $line1->addChild('date', $day . " , " . $month . " , " . $year);
    $line1->addChild('venue', $venue);
    $line1->addChild('area', $area);
    $line1->addChild('Link', $link);
    $line1->addChild('Price', $price);

were is says "HERE HERE HERE!!!!!" I need to add in the id , Can some one help ?

Also the id need to follow the highest number so say if the latest is 20 the new one has to be 21

+1  A: 

Assuming the gigs are in an array:

$num_gigs = count($gigs);
for ($i = 0; $i < $num_gigs; $i++)
{
    $line1 = $sxe->addChild('gig');
    $line1->addChild('id', $i);
    $line1->addChild('date', $day . " , " . $month . " , " . $year);
    $line1->addChild('venue', $venue);
    $line1->addChild('area', $area);
    $line1->addChild('Link', $link);
    $line1->addChild('Price', $price);

}
John Conde
I get the following error syntax error, unexpected '<', expecting T_VARIABLE or '$
Oliver Bayes-Shelton
There was a typo. I fixed it
John Conde