Jump to content

Reading xml


phpcharlie

Recommended Posts

Hey guys, I'd really appreciate some help with this one!

 

my xml file goes something like this:

<directory>

                <item>

                        <1>a1</1>

                        <2>b2</2>

                        <3>c3</3>

                        <4>d4</4>

                </item>

                <item>

                        <1>x1</1>

                        <2>y2</2>

                        <3>z3</3>

                </item>

</directory>

 

How can I get my php to list out all of the values in the order "<2>, <1>, <3>, <4>"???

 

I've tried so many ways, but the best I can do is listing the items in the order that they appear in the xml file, which is really annoying!

 

 

thanks for your help

 

Link to comment
https://forums.phpfreaks.com/topic/208398-reading-xml/
Share on other sites

If you want to alter sequence of only first two records you can use two quires.

 

 SELECT * from tbl_products Where somthing='anything' order by id DESC Limit 2

 

After that

 

 SELECT * from tbl_products Where somthing='anything' order by id ASC Limit 3,20

 

IF you are working with database :)

Link to comment
https://forums.phpfreaks.com/topic/208398-reading-xml/#findComment-1089018
Share on other sites

If you want to alter sequence of only first two records you can use two quires.

 

 SELECT * from tbl_products Where somthing='anything' order by id DESC Limit 2

 

After that

 

 SELECT * from tbl_products Where somthing='anything' order by id ASC Limit 3,20

 

He's not working with a database. He's using an XML file.

Link to comment
https://forums.phpfreaks.com/topic/208398-reading-xml/#findComment-1089019
Share on other sites

If you want to alter sequence of only first two records you can use two quires.

 

 SELECT * from tbl_products Where somthing='anything' order by id DESC Limit 2

 

After that

 

 SELECT * from tbl_products Where somthing='anything' order by id ASC Limit 3,20

 

IF you are working with database :)

 

No database I'm afraid, XML! Thanks anyway though inversesoft123

Link to comment
https://forums.phpfreaks.com/topic/208398-reading-xml/#findComment-1089028
Share on other sites

It is truly shocking code! I havent been phping for long...

 

$xml = simplexml_load_file("myfile.xml");

foreach($xml->children() as $item)

foreach($xml->children()->children() as $child)
  {
  echo $child->getName() . ": " . $child . "<br />";
  }

 

This outputs the following:

1:a1
2:b2
3:c3
4:d4
1:x1
2:y2
3:z3

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/208398-reading-xml/#findComment-1089070
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.