2017-02-14 27 views
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; 

回答

-1

我们决定做一个生成XML按钮,并把它连接到C#的页面,我们导出XML文件。