phpcharlie Posted July 21, 2010 Share Posted July 21, 2010 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 Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted July 21, 2010 Share Posted July 21, 2010 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 Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 21, 2010 Share Posted July 21, 2010 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. Quote Link to comment Share on other sites More sharing options...
phpcharlie Posted July 21, 2010 Author Share Posted July 21, 2010 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 Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 21, 2010 Share Posted July 21, 2010 What is the code you have at the moment? Quote Link to comment Share on other sites More sharing options...
phpcharlie Posted July 21, 2010 Author Share Posted July 21, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.