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;