I am trying to use the get method to get the data from database and show in xml format, but there is a problem. When I going to type (?format=xml&&lang=eng&&no=2) on the link, it will show the records of row 1 & 2. It cannot show only row 2 in the page. And here is the code ,hoping that you guys can give me a helping hand to solve the code problem.
I purpose that enter $no=64 and just show row 64 record from database only but not 1 to 64 row.
$format = $_GET["format"];
$no = $_GET["no"];
$lang=$_GET["lang"];
if($format == "xml" && $lang=="eng" ){
header('Content-type: application/xml');
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
$sql ="SELECT * FROM station ";
$result= mysql_query($sql);
$xml->startElement('stationList');
if (isset($_GET["no"])){
while ($row = mysql_fetch_assoc($result)) {
if($row["no"] == $no){
$xml->startElement("station");
$xml->writeAttribute('no', $no);
$xml->writeElement('loctation',$row['location']);
$xml->writeElement('lat',$row['lat']);
$xml->writeElement('lng',$row['lng']);
$xml->writeElement('type',$row['type']);
$xml->writeElement('districtL',$row['districtL']);
$xml->writeElement('districtS',$row['districtS']);
$xml->writeElement('address',$row['address']);
$xml->writeElement('provider',$row['provider']);
$xml->writeElement('parkingNo',$row['parkingNo']);
$xml->writeElement('img',$row['img']);
$xml->endElement();
break;
break;
}else{
$xml->startElement("station");
$xml->writeAttribute('no', $row['no']);
$xml->writeElement('loctation',$row['location']);
$xml->writeElement('lat',$row['lat']);
$xml->writeElement('lng',$row['lng']);
$xml->writeElement('type',$row['type']);
$xml->writeElement('districtL',$row['districtL']);
$xml->writeElement('districtS',$row['districtS']);
$xml->writeElement('address',$row['address']);
$xml->writeElement('provider',$row['provider']);
$xml->writeElement('parkingNo',$row['parkingNo']);
$xml->writeElement('img',$row['img']);
$xml->endElement();
}
}
}
$xml->endElement();
$xml->endDocument();
$xml->flush();
}
Aucun commentaire:
Enregistrer un commentaire