【发布时间】:2017-12-21 07:58:49
【问题描述】:
我有以下查询,它从 mysql 表中搜索数据并使用 php 导出到 XML,但我不知道如何将记录数传递给 xml 中的 MatchCount 元素。
下面是我的脚本:
<?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;
?>
【问题讨论】:
-
在哪里执行查询,知道什么是字符串拼接,知道sql可以做什么吗?
-
请查看我编辑的查询
-
你想显示行数吗?
-
是的,请开发者先生