2017-12-21 9 views
0

私は以下のクエリを使ってmysqlテーブルからデータを検索し、PHPを使用してXMLにエクスポートしますが、レコードカウントをMatchCount要素に渡す方法はわかりませんxml。SQLからのレコード数を取得し、PHPを使ってxmlに渡す

以下

は私のスクリプトです:

<?php 
header ("content-type: text/xml"); 
$connection = mysqli_connect('127.0.0.1', 'root', 'admin', 'Customer_1') or die("cannot connect"); 

$xml='<?xml version="1.0" encoding="UTF-8"?>'; 

$RegistrationMark = $_GET['RegistrationMark']; 
$MachineName = $_GET['MachineName']; 



$qr= mysqli_query($connection, "SELECT * FROM `EarlsdonMSIN_anpr_vega` where `RegistrationMark` like '%" .$RegistrationMark. "%'"); 

$xml.='<CaptureResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\CaptureResponse.xsd"> <MachineName>'.$_GET['MachineName'].'</MachineName><MatchCount>10</MatchCount><ResponseDateTime>2017-12-20T14:00:00</ResponseDateTime><MatchRecords ImageURI = "http://192.192.192.200/share/CACHEDEV1_DATA/Lanein1/EarlsdonMSIN/">'; 

while($res=mysqli_fetch_array($qr)) 
{ 
$xml.='<MatchLine><VehicleRegistration>'.$res['RegistrationMark'].'</VehicleRegistration><LastStatus>IN</LastStatus><datetime>'.$res['datetime'].T.$res['time'].'</datetime><ImageFile>'.$res['image_name'].'</ImageFile></MatchLine>'; 
} 

$xml.='</MatchRecords></CaptureResponse>'; 
echo $xml; 
?> 
+0

ここで、クエリを実行しますか、文字列連結が何であるか知っていますか? – madalinivascu

+0

私の編集したクエリをご覧ください – preethi

+0

行数を表示しますか? –

答えて

0

あなたは、カウント

$row_cnt = mysqli_num_rows($qr); 

を取得する必要があり、あなたは結果

$xml.='<CaptureResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\CaptureResponse.xsd"> <MachineName>'.$_GET['MachineName'].'</MachineName><MatchCount>'.$row_cnt.'</MatchCount><ResponseDateTime>2017-12-20T14:00:00</ResponseDateTime><MatchRecords ImageURI = "http://192.192.192.200/share/CACHEDEV1_DATA/Lanein1/EarlsdonMSIN/">'; 
+1

ありがとうmadalinivascu。出来た。 – preethi

+0

xml..resaseのresposedatetimeに現在時刻を取得する方法を教えてもらえますか? – preethi

+0

http://php.net/manual/ro/function.time.php – madalinivascu

0

PHPを連結する必要があるローをカウントするためのmysqli_num_rows()を提供クエリに応じて、あなたはあなたの後にそれを使用することができますmysqli_query()

$MatchCount=mysqli_num_rows($qr); 

その後10$MatchCountを交換し、連結、これを試してみてください。以下は例です

$xml.='<CaptureResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\CaptureResponse.xsd"> <MachineName>'.$_GET['MachineName'].'</MachineName><MatchCount>'.$MatchCount.'</MatchCount><ResponseDateTime>2017-12-20T14:00:00</ResponseDateTime><MatchRecords ImageURI = "http://192.192.192.200/share/CACHEDEV1_DATA/Lanein1/EarlsdonMSIN/">'; 
関連する問題