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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.