bishmedia Posted February 3, 2013 Share Posted February 3, 2013 ok all you phpfreaks, im hoping one of you can help me :-) ive started a simple xml file and php file to read and view as below.... <?xml version="1.0" encoding="ISO-8859-1"?> <datas> <comp> <result> <year>2013</year> <compName>Butlins Mineworkers</compName> <bandName>GUS Virtuoso</bandName> <position>1st</position> <points>2</points> </result> <result> <year>2013</year> <compName>Butlins Mineworkers</compName> <bandName>GUS Virtuoso</bandName> <position>2nd</position> <points>4</points> </result> <result> <year>2013</year> <compName>Butlins Mineworkers</compName> <bandName>Carlton Main Frickley Colliery</bandName> <position>3rd</position> <points>6</points> </result> </comp> </datas> <?php $xml = simplexml_load_file("xmltestdata.xml") or die("Error: Cannot create object"); foreach($xml->children() as $result){ foreach($result->children() as $result => $data){ echo $data->year; echo $data->compName; echo $data->bandName; echo $data->position; echo $data->points; echo "<br />"; } } ?> In time the xml will grow and my question is, what if a user wanted to view results for a specific band 'bandName' via say a 'Drop Down Box?? I do hope theres someone out there in cyber who can help Many Thanks in advance. Bish Link to comment https://forums.phpfreaks.com/topic/273978-searching-xml-files/ Share on other sites More sharing options...
Barand Posted February 3, 2013 Share Posted February 3, 2013 <?php $xml = simplexml_load_file('xmltestdata.xml'); $search = 'GUS Virtuoso'; $results = $xml->xpath("//result[bandName='$search']"); foreach ($results as $res) { echo "$res->compName $res->year $res->position <br>"; } RESULTS Butlins Mineworkers 2013 1st Butlins Mineworkers 2013 2nd Link to comment https://forums.phpfreaks.com/topic/273978-searching-xml-files/#findComment-1409845 Share on other sites More sharing options...
bishmedia Posted February 3, 2013 Author Share Posted February 3, 2013 Many many thanks, that brilliant, i will try this later and move on to another problem im sure :-) Link to comment https://forums.phpfreaks.com/topic/273978-searching-xml-files/#findComment-1409846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.