Malcolmhire2001 Posted January 12, 2007 Share Posted January 12, 2007 hello again,what i am trying to do is to post some variables from a search form (seprate file) to some script that processes query using Xpath.the variables are working fine as i echoed them out, i just want the query to display the same data that is stored in my XML file using for example $type variable this would either be cottage, hotel, boat ect and say "Hotel" was stored in the variable then display the infomation about all the Hotel holidays.if anyone could help it would be great.Query Code:[code]<!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" xml:lang="en" lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CG0119 Week 10, Task 2</title></head><body><?phpecho $type = $_POST['type'];echo $destination = $_POST['destination'];echo $ckin = $_POST['ckin'];echo $ckout = $_POST['ckout'];echo $rooms = $_POST['rooms'];echo $adult = $_POST['adult'];echo $children = $_POST['children'];echo $min = $_POST['min'];echo $max = $_POST['max']; // ************************ // *** PROCESS THE FORM *** // ************************ $doc = new DOMDocument; $doc->preserveWhiteSpace = false; $doc->Load('holidays.xml'); $xpath = new DOMXPath($doc); // Create the query string based on which option the user selected // (start at the root element and include a condition if required). if ("$type") { $query = '//students/student/studyTypeID[. = "$type"]'; // Execute the query and return a DOMNodeList containing all // of the nodes that match the XPath expression. $entries = $xpath->query($query); echo "<ul>\n"; // Display the required values for each entry returned by the XPath query. foreach ($entries as $entry) { echo "<li>{$entry->nodeValue}</li>\n"; } echo "</ul>\n"; } // close the process the form if statement?></body></html>[/code] XML Code:[code]<?xml version="1.0" ?><holidays> <holiday> <holidaycode>C1257</holidaycode> <type>Cottage</type> <maxsleeps>8</maxsleeps> <company>Allseasons</company> <location>Fulbeck, Northumberland</location> <dates> <date> <startdate>29-10-2006</startdate> <enddate>31-10-2006</enddate> <duration>3</duration> <costprice>419</costprice> </date> <date> <startdate>12-11-2006</startdate> <enddate>14-11-2006</enddate> <duration>3</duration> <costprice>419</costprice> </date> <date> <startdate>08-04-2007</startdate> <enddate>10-04-2007</enddate> <duration>3</duration> <costprice>621</costprice> </date> <date> <startdate>28-05-2007</startdate> <enddate>04-06-2007</enddate> <duration>5</duration> <costprice>1045</costprice> </date> <date> <startdate>01-08-2007</startdate> <enddate>07-08-2007</enddate> <duration>7</duration> <costprice>1242</costprice> </date> </dates> </holiday> <holiday> <holidaycode>C4981</holidaycode> <type>Cottage</type> <maxsleeps>6</maxsleeps> <company>NewHolidays</company> <location>Old Cornsay, County Durham</location> <dates> <date> <startdate>21-12-2006</startdate> <enddate>27-12-2006</enddate> <duration>7</duration> <costprice>569</costprice> </date> <date> <startdate>14-02-2007</startdate> <enddate>16-02-2007</enddate> <duration>3</duration> <costprice>250</costprice> </date> <date> <startdate>03-06-2007</startdate> <enddate>09-06-2007</enddate> <duration>7</duration> <costprice>427</costprice> </date> <date> <startdate>22-07-2007</startdate> <enddate>24-07-2007</enddate> <duration>3</duration> <costprice>453</costprice> </date> <date> <startdate>16-09-2007</startdate> <enddate>22-09-2007</enddate> <duration>7</duration> <costprice>416</costprice> </date> </dates> </holiday> <holiday> <holidaycode>C2529</holidaycode> <type>Cottage</type> <maxsleeps>4</maxsleeps> <company>DorsetHols</company> <location>North Beaminster, Dorset</location> <dates> <date> <startdate>14-10-2007</startdate> <enddate>20-10-2007</enddate> <duration>7</duration> <costprice>313</costprice> </date> <date> <startdate>20-08-2007</startdate> <enddate>26-08-2007</enddate> <duration>7</duration> <costprice>629</costprice> </date> <date> <startdate>03-01-2007</startdate> <enddate>05-01-2007</enddate> <duration>3</duration> <costprice>569</costprice> </date> <date> <startdate>04-11-2006</startdate> <enddate>10-11-2006</enddate> <duration>7</duration> <costprice>280</costprice> </date> <date> <startdate>10-04-2007</startdate> <enddate>12-04-2007</enddate> <duration>3</duration> <costprice>307</costprice> </date> </dates> </holiday> <holiday> <holidaycode>B2389</holidaycode> <type>Boating</type> <maxsleeps>7</maxsleeps> <company>ElvinBoats</company> <location>River Bure, Horning, Norfolk</location> <dates> <date> <startdate>02-07-2007</startdate> <enddate>08-07-2007</enddate> <duration>7</duration> <costprice>995</costprice> </date> <date> <startdate>19-08-2007</startdate> <enddate>25-08-2007</enddate> <duration>7</duration> <costprice>1242</costprice> </date> <date> <startdate>15-05-2007</startdate> <enddate>17-05-2007</enddate> <duration>3</duration> <costprice>530</costprice> </date> <date> <startdate>25-03-2007</startdate> <enddate>27-03-2007</enddate> <duration>3</duration> <costprice>432</costprice> </date> <date> <startdate>02-09-2007</startdate> <enddate>08-09-2007</enddate> <duration>7</duration> <costprice>978</costprice> </date> </dates> </holiday> <holiday> <holidaycode>B1078</holidaycode> <type>Boating</type> <maxsleeps>6</maxsleeps> <company>FloatingHols</company> <location>River Bure, Wroxham, Norfolk</location> <dates> <date> <startdate>24-06-2007</startdate> <enddate>30-06-2007</enddate> <duration>7</duration> <costprice>682</costprice> </date> <date> <startdate>29-10-2006</startdate> <enddate>31-10-2006</enddate> <duration>3</duration> <costprice>419</costprice> </date> <date> <startdate>15-04-2007</startdate> <enddate>21-04-2007</enddate> <duration>7</duration> <costprice>680</costprice> </date> <date> <startdate>03-06-2007</startdate> <enddate>09-06-2007</enddate> <duration>7</duration> <costprice>853</costprice> </date> <date> <startdate>08-09-2006</startdate> <enddate>10-09-2006</enddate> <duration>3</duration> <costprice>476</costprice> </date> </dates> </holiday> <holiday> <holidaycode>B0988</holidaycode> <type>Boating</type> <maxsleeps>6</maxsleeps> <company>Andersons</company> <location>River Ant, Stalham, Norfolk</location> <dates> <date> <startdate>17-06-2007</startdate> <enddate>23-06-2007</enddate> <duration>7</duration> <costprice>930</costprice> </date> <date> <startdate>22-07-2007</startdate> <enddate>28-07-2007</enddate> <duration>7</duration> <costprice>1190</costprice> </date> <date> <startdate>10-05-2007</startdate> <enddate>12-05-2007</enddate> <duration>3</duration> <costprice>530</costprice> </date> <date> <startdate>23-07-2007</startdate> <enddate>25-07-2007</enddate> <duration>3</duration> <costprice>884</costprice> </date> <date> <startdate>02-09-2006</startdate> <enddate>08-09-2006</enddate> <duration>7</duration> <costprice>840</costprice> </date> </dates> </holiday> <holiday> <holidaycode>L4390</holidaycode> <type>Lodge</type> <maxsleeps>6</maxsleeps> <company>LejkHolidays</company> <location>Seaton, Looe, Cornwall</location> <dates> <date> <startdate>10-06-2007</startdate> <enddate>16-06-2007</enddate> <duration>7</duration> <costprice>350</costprice> </date> <date> <startdate>22-07-2007</startdate> <enddate>28-07-2007</enddate> <duration>7</duration> <costprice>620</costprice> </date> <date> <startdate>10-05-2007</startdate> <enddate>12-05-2007</enddate> <duration>3</duration> <costprice>145</costprice> </date> <date> <startdate>23-07-2007</startdate> <enddate>25-07-2007</enddate> <duration>3</duration> <costprice>409</costprice> </date> <date> <startdate>02-09-2006</startdate> <enddate>08-09-2006</enddate> <duration>7</duration> <costprice>293</costprice> </date> </dates> </holiday> <holiday> <holidaycode>CA852</holidaycode> <type>Caravan</type> <maxsleeps>8</maxsleeps> <company>EllmanGetaways</company> <location>Hopton on Sea, Norfolk</location> <dates> <date> <startdate>01-04-2007</startdate> <enddate>07-04-2007</enddate> <duration>7</duration> <costprice>379</costprice> </date> <date> <startdate>10-05-2007</startdate> <enddate>16-05-2007</enddate> <duration>7</duration> <costprice>339</costprice> </date> <date> <startdate>20-08-2007</startdate> <enddate>22-08-2007</enddate> <duration>3</duration> <costprice>829</costprice> </date> <date> <startdate>02-09-2007</startdate> <enddate>08-09-2007</enddate> <duration>7</duration> <costprice>504</costprice> </date> <date> <startdate>15-07-2007</startdate> <enddate>17-07-2007</enddate> <duration>3</duration> <costprice>489</costprice> </date> </dates> </holiday> <holiday> <holidaycode>L9023</holidaycode> <type>Lodge</type> <maxsleeps>8</maxsleeps> <company>EllmanGetaways</company> <location>Darsham, Suffolk</location> <dates> <date> <startdate>03-04-2007</startdate> <enddate>09-04-2007</enddate> <duration>7</duration> <costprice>175</costprice> </date> <date> <startdate>14-05-2007</startdate> <enddate>20-05-2007</enddate> <duration>7</duration> <costprice>256</costprice> </date> <date> <startdate>18-08-2007</startdate> <enddate>20-08-2007</enddate> <duration>3</duration> <costprice>357</costprice> </date> <date> <startdate>05-09-2007</startdate> <enddate>11-09-2007</enddate> <duration>7</duration> <costprice>268</costprice> </date> <date> <startdate>10-07-2007</startdate> <enddate>12-07-2007</enddate> <duration>3</duration> <costprice>276</costprice> </date> </dates> </holiday> <holiday> <holidaycode>C7845</holidaycode> <type>Caravan</type> <maxsleeps>6</maxsleeps> <company>EssexHolidays</company> <location>St Osyth, Clacton-on-Sea, Essex</location> <dates> <date> <startdate>22-04-2007</startdate> <enddate>24-04-2007</enddate> <duration>3</duration> <costprice>204</costprice> </date> <date> <startdate>07-05-2007</startdate> <enddate>13-05-2007</enddate> <duration>7</duration> <costprice>341</costprice> </date> <date> <startdate>26-08-2007</startdate> <enddate>28-08-2007</enddate> <duration>3</duration> <costprice>506</costprice> </date> <date> <startdate>03-09-2007</startdate> <enddate>09-09-2007</enddate> <duration>7</duration> <costprice>451</costprice> </date> <date> <startdate>15-07-2007</startdate> <enddate>21-07-2007</enddate> <duration>7</duration> <costprice>676</costprice> </date> </dates> </holiday> <holiday> <holidaycode>HEB01</holidaycode> <type>Hotel</type> <maxsleeps>2</maxsleeps> <company>Edwardian Grand</company> <location>Oxford Street, London</location> <dates> <date> <startdate>14-11-2006</startdate> <enddate>15-11-2006</enddate> <duration>1</duration> <costprice>185</costprice> </date> <date> <startdate>14-11-2006</startdate> <enddate>16-11-2006</enddate> <duration>2</duration> <costprice>350</costprice> </date> <date> <startdate>26-08-2007</startdate> <enddate>01-09-2007</enddate> <duration>7</duration> <costprice>1200</costprice> </date> </dates> </holiday> <holiday> <holidaycode>H2589</holidaycode> <type>Hotel</type> <maxsleeps>2</maxsleeps> <company>Hotel Mikko</company> <location>Marble Arch, London</location> <dates> <date> <startdate>12-12-2006</startdate> <enddate>13-12-2006</enddate> <duration>1</duration> <costprice>140</costprice> </date> <date> <startdate>22-11-2006</startdate> <enddate>24-11-2006</enddate> <duration>2</duration> <costprice>255</costprice> </date> <date> <startdate>20-08-2007</startdate> <enddate>26-08-2007</enddate> <duration>7</duration> <costprice>900</costprice> </date> </dates> </holiday> <holiday> <holidaycode>H3892</holidaycode> <type>Hotel</type> <maxsleeps>4</maxsleeps> <company>Swansea Inn</company> <location>Swansea</location> <dates> <date> <startdate>12-12-2006</startdate> <enddate>13-12-2006</enddate> <duration>1</duration> <costprice>74</costprice> </date> <date> <startdate>22-11-2006</startdate> <enddate>24-11-2006</enddate> <duration>2</duration> <costprice>130</costprice> </date> <date> <startdate>20-08-2007</startdate> <enddate>26-08-2007</enddate> <duration>7</duration> <costprice>450</costprice> </date> </dates> </holiday> <holiday> <holidaycode>H5840</holidaycode> <type>Hotel</type> <maxsleeps>3</maxsleeps> <company>Burns Hotel</company> <location>Glasgow</location> <dates> <date> <startdate>12-12-2006</startdate> <enddate>13-12-2006</enddate> <duration>1</duration> <costprice>42</costprice> </date> <date> <startdate>18-11-2006</startdate> <enddate>20-11-2006</enddate> <duration>2</duration> <costprice>75</costprice> </date> <date> <startdate>17-09-2007</startdate> <enddate>23-09-2007</enddate> <duration>7</duration> <costprice>280</costprice> </date> </dates> </holiday></holidays>[/code] Link to comment https://forums.phpfreaks.com/topic/33908-parsing-xml-using-variables/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.