millsy007 Posted December 3, 2008 Share Posted December 3, 2008 I have php code that uses an XML file to display in an HTML page the 'Next' and 'Previous' pages for that page. The code currently selects ALL of the XML records and then displays them on the page. What I would like to be able to do is have the HTML only display the next and previous links for the current page. What would be the best way to do this? Perhaps Select only where the XML Title = the HTML page title? ??? XML <?xml version="1.0" encoding="ISO-8859-1"?> <Listings> <Count>2</Count> <Listing> <Title><![CDATA[Food and Drink]]></Title> <PREVURI>http://www.page.nl</PREVURI> <NEXTURI>http://www.page.nl/info/Location.php</NEXTURI> </Listing> <Listing> <Title><![CDATA[Location]]></Title> <PREVURI>http://www.page.nl/Food-and-Drink/index.php</PREVURI> <NEXTURI>http://www.page.nl/info/Facilities.php</NEXTURI> </Listing> </Listings> PHP <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php // read xml file into string $text = file_get_contents("sample.xml"); if(!$text) { die("ERROR: Unable to read file"); } // parse the xml into structure $p = xml_parser_create(); xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); xml_parse_into_struct($p, $text, $vals, $index); xml_parser_free($p); // read data of interest from structure into array: for($i=0; $i<$index['Listings'][1]; $i++) { foreach(array('Title', 'PREVURI', 'NEXTURI') as $key) { $data[$i][$key] = $vals[$index[$key][$i]]['value']; } } // output HTML: foreach($data as $val) { echo <<<XML <a href="{$val['PREVURI']}"><small>PREVIOUS</small></a> <h3>{$val['Title']}</h3> <a href="{$val['NEXTURI']}"><small>NEXT</small></a> <br> XML; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/135316-selecting-the-current-xml-record/ Share on other sites More sharing options...
millsy007 Posted December 4, 2008 Author Share Posted December 4, 2008 Would it just be a case of modifying this line: for($i=0; $i<$index['Listings'][1]; $i++) To only pass in the number eg ['Listings'][5] for the page I wanted and then remove the increment ; $i++ ? Link to comment https://forums.phpfreaks.com/topic/135316-selecting-the-current-xml-record/#findComment-705776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.