我在SQL中显示表中的订单。当检查一行或多行并使用按钮提交(我还需要提交按钮)时,我想生成一个XML文件。
$query = "SELECT SH.[Your Reference]
,SH.[Name]
,SIL.[Description]
,SIL.[Service Item Group Code]
,SIL.[Serial No_]
,SH.[Address]
,SH.[City]
,[No_]
,CASE SIL.[Claim]
WHEN 1 THEN 'Ja'
WHEN 0 THEN 'Nee' END [Claim]
FROM
[dbo].[cache\$Service Header] SH INNER JOIN
[cache\$Service Item Line] SIL ON SH.[Document Type] = SIL.[document type] AND SH.[No_] = SIL.[Document No_]
WHERE [Repair Status Code] = '53'";
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$result = sqlsrv_query($conn, $query, $params,$options);
if (!sqlsrv_num_rows($result)) {
echo 'No records found';
} else {
?>
<table border="1">
<thead>
<tr>
<th>Garantie</th>
<th>Serviceordernummer</th>
<th>Referentie</th>
<th>Serviceartikelgroepcode</th>
<th>Omschrijving</th>
<th>Serienummer</th>
<th>Naam</th>
<th>Adres</th>
<th>Plaats</th>
<th>Ruilkaart</th>
</tr>
</thead>
<tbody>
<?php
while ($row = sqlsrv_fetch_array($result)) {
echo'<tr>';
echo'<td>'.$row['Claim'].'</td>';
echo'<td>'.$row['No_'].'</td>';
echo'<td>'.$row['Your Reference'].'</td>';
echo'<td>'.$row['Service Item Group Code'].'</td>';
echo'<td>'.$row['Description'].'</td>';
echo'<td>'.$row['Serial No_'].'</td>';
echo'<td>'.$row['Name'].'</td>';
echo'<td>'.$row['Address'].'</td>';
echo'<td>'.$row['City'].'</td>';
echo "<td><input type=\"checkbox\" name=\"ruilkaart\" class=\"radio\" value=\"ruilkaart\"></td>";
echo'<tr>';
}
?>
</tbody>
</table>
<?php
}
?>
XML文件必须包含以下字段。我真的不知道从哪里开始。有没有人可以指导我这个?
<xml xmlns="http://www.to-increase.com/data/blocks" contentnamespace="NAV">
<blocks>
<block id="Main">
<members>
<member id="DocumentNo">485250</member>
<member id="LineNo">10000</member>
<member id="RepairStatusCodeIn">80</member>
<member id="RepairStatusCodeOut">93</member>
<member id="ServiceItemGroupCodeOut">7678</member>
<member id="ItemNoOut">A010146</member>
<member id="SerialNoOut">TEST2_SN</member>
<member id="ExchangeReasonCode">D</member>
<member id="ApprovalNumber">App_test</member>
<member id="SectionCode">COMM: SET</member>
<member id="DefectCode">COMM: 2</member>
<member id="ResolutionCode">COMM: Z</member>
</members>
<blocks>
<block id="ServiceItemLineOut">
<blocks>
<block id="ServiceItemOut"/>
<block id="ServiceLineOut"/>
</blocks>
</block>
</blocks>
</block>
</blocks>
</xml>
@Sandip Patel
i followed the instructions. But somewhere i forgot something. Can't find the missing part.
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
End tag 'tblPortalStatus' does not match the start tag 'body'. Error processing resource 'http://PHP/Form...
<?xml version="1.0" encoding="UTF-8"?></tblPortalStatus>
----------------------------------------^
我的代码现在是:
if (!sqlsrv_num_rows($result)) {
die('Invalid query: ' . sqlsrv_error());
}
if(sqlsrv_num_rows($result)>0)
{
while($result_array = sqlsrv_fetch_assoc($result))
{
$xml .= "<".$config['table_name'].">";
//loop through each key,value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml .= "<$key>";
//embed the SQL data in a CDATA element to avoid XML entity issues
$xml .= "<![CDATA[$value]]>";
//and close the element
$xml .= "</$key>";
}
$xml.= "<".$config['table_name'].">";
}
}
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$root_element = "tblPortalStatus";
//close the root element
$xml .= "</tblPortalStatus>";
//send the xml header to the browser
header ("Content-Type:text/xml");
//output the XML data
echo $xml;
答案 0 :(得分:-1)
我们决定创建一个生成xml按钮并将其连接到我们导出XML文件的C#页面。