php - retrieving xml data -
in stores.htm
, have input 2 values: 1 street address (streetno , street name) , other suburb. on basis of providing inputs, retrieves data stores.xml
file.
the problem street address , suburb both stored in <address>
element of stores.xml
file, not separately. tried lot i'm not finding solution of how match inputs xml file data.
i stuck in if (condition)
which in php file
stores.xml
<?xml version="1.0" ?> <stores> <store> <name>galaxy</name> <address>50 callander road,noble park</address> </store> <store> <name>remica</name> <address>10 challander road,noble park</address> </store> <store> <name>home</name> <address>10/10 callan road,richmond</address> </store> </stores>
stores.htm
<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>search</title> <script type="text/javascript" src="search.js"></script> </head> <body> <form> enter street address: <input type="text" name="street" /> enter suburb : <input type="text" name="suburb" /> <input name="submit" type = "button" onclick = "getdata('search.php','info', street.value, suburb.value)" value = "search" /> </form> <div id="info" /> </body> </html>
search.php
$street= $_post["str"]; $suburb= $_post["sub"]; $xmlfile = "stores.xml"; $doc= domdocument::load($xmlfile); $store = $doc->getelementsbytagname("store"); echo "<table border=1><tr><th>name</th></tr>"; foreach($store $node) { $name = $node->getelementsbytagname("name"); $name = $name->item(0)->nodevalue; $address = $node->getelementsbytagname("address"); $address = $address->item(0)->nodevalue; if( /* goes here? */ ) { echo"<tr><td>name</td></tr>"; } echo "</table>";
you can use php's explode function separate street address suburb.
// split address 2 parts, street , suburb, using delimiter ',' $address_split = explode(',', $address); $address_street = $address_split[0]; $address_suburb = $address_split[1]; if ($address_street == $street && $address_suburb == $suburb) { // code here }
Comments
Post a Comment