html - Trying to get the id of XML when button is clicked and list the contents on another page PHP -
i'm trying id the hotellist.php page. i'm not sure how in xml since i'm new it. please explain.
<?php $xml=simplexml_load_file("data.xml") or die("error: cannot create object"); foreach($xml->children() $hotels) { echo "<tr><td width='20%'><img src='".$hotels->image."'></td>"; echo "<td width='60%'><h1>".$hotels->name."</h1><h3>"; echo $hotels->address . "</h3></td>"; echo "<td width='20%'><table id='price'><tr><td><h1>$".$hotels->price . "</h1></td></tr>"; echo "<tr><td><a href=hotel.php?id=". $hotels->id ."><img src='image/btn_viewdetails.jpg'/></a></table></td></tr>"; } ?>
and make full contents appear in hotel.php
here xml
<?xml version="1.0" encoding="utf-8"?> <hotellist> <hotel> <id>1</id> <image>image/hotel/orchidgardenhotel.jpg</image> <name>rizqun hotel</name> <address>no. 15, spg 447, kg kapok, jalan muara</address> <phone>8655425</phone> <price>60</price> </hotel> <hotel> <id>2</id> <image>image/hotel/orchidgardenhotel.jpg</image> <name>orchid hotel</name> <address>no. 15, spg 447, kg kapok, jalan muara</address> <phone>8655425</phone> <price>420</price> </hotel> </hotellist>
try following code:
$id = $_request['id']; $xml=simplexml_load_file("data.xml") or die("error: cannot create object"); $hotels = $xml->xpath("//hotellist/hotel[id='{$id}']"); foreach($hotels $hotel) { echo $hotel->image . "\n"; echo $hotel->name . "\n"; echo $hotel->address . "\n"; echo "$".$hotel->price . "\n"; echo $hotel->id . "\n"; }
Comments
Post a Comment