1
我在SQL中顯示錶中的訂單。當一行或多行檢查並提交一個按鈕(我也需要一個提交按鈕)我想生成一個XML文件。從SQL表中使用PHP創建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帕特爾
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;