2017-02-14 33 views
1

我是新來的PHP,並試圖使一些有用的爲我們的辦公部門檢索表B中的數據。 我想在頁面A上顯示的信息是來自MSSQL表A的數據。這是關於修復狀態53.使MSSQL中的數據池(表一)點擊並在新頁面

員工檢查此列表,單擊Document no(order)並獲取有關具體信息的更多信息從表B的訂單。表B有關於客戶和訂單的更多信息。

我正在努力與我可以創建的鏈接。

這裏的代碼如下。

$query = "SELECT [Document No_],[Service Item No_],[Description],[Serial No_] FROM [dbo].[cache\$Service Item Line] 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>Servicenumber</th> 
       <th>Service item</th> 
       <th>Description</th> 
       <th>Serialnumber</th> 
      </tr> 
     </thead> 
     <tbody> 
     <?php 
      while ($row = sqlsrv_fetch_array($result)) { 
       echo'<tr>'; 
       echo'<td>'. $row['Document No_']."</td>"; 
       echo'<td>'. $row['Service Item No_'].'</td>'; 
       echo'<td>'. $row['Description'].'</td>'; 
       echo'<td>'. $row['Serial No_'].'</td>'; 
       echo'<tr>'; 
      } 
     ?> 
     </tbody> 
    </table> 
    <?php 
} 
?> 

我需要在php中添加此代碼。在SQL它工作正常,但是當我加入這個我的PHP文件,我刷新頁面

SELECT 

    [Name] 
    ,[Address] 
    ,[Post Code] 
    ,[City] 
    ,[Your Reference] 
    ,[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.[No_] = SIL.[Document No_] 
WHERE [Repair Status Code] = '53' 
+0

你得到了什麼錯誤 – gaurav

+0

@gaurav我沒有得到任何錯誤。這顯示了我的數據表,並確定,但我希望[document no_]是可點擊的。當我點擊它時,我必須進入一個關於該文檔no_的信息的新頁面。 我嘗試了這種方式:回聲​​''.$row['Document No_'].'''; 但這不起作用,因爲我使用的代碼是不正確的。我的第一頁不顯示任何內容。 – Sergio

回答

0

,當我設法得到它與下面的代碼工作得到了內部服務器錯誤。 我將爲一個新問題開闢一個新話題。

$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 
} 
?> 
相關問題