auto increment for simpleXML
I have my simpleXML script creating new element's in a xml file but I need the attribute to be a auto incr开发者_如何学JAVAemented 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
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);
}
精彩评论