2013-08-18 58 views
0

我試圖顯示兩個表格,其中顯示了不同的數據集合。第一個表格只是一行顯示有關發票的信息。第二個表格顯示發票中包含的所有項目。目前頁面正確顯示第一個表格。第二個表是我遇到問題的地方。此表顯示了我想要的所有數據。但它將每個項目顯示爲單獨的表格,而不是表格中的行。有人可以看看我的代碼,並可能幫助我弄清楚在哪裏存在?由於使用單獨的SQL查詢顯示兩個表格

<?php 

$storeid = $_GET['store_id']; 
$invoiceid = $_GET['invoice_id']; 
$suppid = $_GET['supp_id']; 

$strSecReq  = '1'; 
$strDptReq  = 'ANY'; 
$strRequester = $_SERVER['PHP_SELF']; 

include ($_SERVER['DOCUMENT_ROOT'] . "/securelogin/logincheck.php"); 
include ($_SERVER['DOCUMENT_ROOT'] . "/database/database.php"); 

$pgtitle = "Invoice # " . $invoiceid . " Detail"; 

include('header.php'); 

$conn = odbc_connect("$storeid", $ODBC_STOREID[1], $ODBC_STOREID[2]) or die ('<br><b>Error Connecting To STORE</b><br>\n'); 

REMOVED SELECT語句,每個公司政策

$rsSQL = odbc_exec($conn, $sql) or die ('<br>Error Executing detail SQL'); 

if (odbc_num_rows($rsSQL)== 0) { 

    echo "<center>"; 
    echo "<br><b>Your Primary Item ID does not match any entries.<br>Please page back and try again.</b>"; 
    echo "</center>"; 

    odbc_close($conn); 
} else { 

    while ($row = odbc_fetch_array($rsSQL)) { 

     echo "<div align='center'>"; 
     echo "<table class ='tablesmall' border='1' align='center' cellpadding='4'>"; 
     echo "<thead>"; 
     echo "<tr>"; 
     echo "<th><b>Supplier</b></th>"; 
     echo "<th><b>Control</b></th>"; 
     echo "<th><b>Type</b></th>"; 
     echo "<th><b>Inv Date</b></th>"; 
     echo "<th><b>Rec Date</b></th>"; 
     echo "<th><b># Lines</b></th>"; 
     echo "<th><b>Dept</b></th>"; 
     echo "<th><b>History</b></th>"; 
     echo "<th><b>Status</b></th>"; 
     echo "<th><b>Start TS</b></th>"; 
     echo "<th><b>End TS</b></th>"; 
     echo "<th><b>User</b></th>"; 
     echo "</tr>"; 
     echo "</thead>"; 

     $SuppNum = trim(odbc_result($rsSQL, "SuppNum")); 
     $ContNum = trim(odbc_result($rsSQL, "ContNum")); 
     $InvType = trim(odbc_result($rsSQL, "InvType")); 
     $InvDate = trim(odbc_result($rsSQL, "InvDate")); 
     $RecDate = trim(odbc_result($rsSQL, "RecDate")); 
     $NumLines = trim(odbc_result($rsSQL, "NumLines")); 
     $DeptNum = trim(odbc_result($rsSQL, "DeptNum")); 
     $HistFlag = trim(odbc_result($rsSQL, "HistFlag")); 
     $InvStat = trim(odbc_result($rsSQL, "InvStat")); 
     $InvStart = trim(odbc_result($rsSQL, "InvStart")); 
     $InvEnd = trim(odbc_result($rsSQL, "InvEnd")); 
     $UserName = trim(odbc_result($rsSQL, "UserName")); 

     echo "<tbody>"; 
     echo "<tr><td>"; 
     echo $SuppNum; 
     echo "</td><td>"; 
     echo $ContNum; 
     echo "</td><td>"; 
     echo $InvType; 
     echo "</td><td>"; 
     echo $InvDate; 
     echo "</td><td>"; 
     echo $RecDate; 
     echo "</td><td>"; 
     echo $NumLines; 
     echo "</td><td>"; 
     echo $DeptNum; 
     echo "</td><td>"; 
     echo $HistFlag; 
     echo "</td><td>"; 
     echo $InvStat; 
     echo "</td><td>"; 
     echo $InvStart; 
     echo "</td><td>"; 
     echo $InvEnd; 
     echo "</td><td>"; 
     echo $UserName; 
     echo "</td></tr>"; 
     echo "</tbody>"; 
     echo "</table>"; 
     echo "</div>"; 
     echo "<br>"; 

REMOVED SELECT語句,每個公司政策

 $rsSQL1 = odbc_exec($conn, $sql1) or die ('<br>Error Executing detail SQL'); 

     while ($row = odbc_fetch_array($rsSQL1)) { 

     echo "<div align='center'>"; 
     echo "<table class ='tablesmall' border='1' align='center' cellpadding='4'>"; 
     echo "<thead>"; 
     echo "<tr>"; 
     echo "<th><b>Seq</b></th>"; 
     echo "<th><b>Type</b></th>"; 
     echo "<th><b>Ord Code</b></th>"; 
     echo "<th><b>ItemID</b></th>"; 
     echo "<th><b>Sku Type</b></th>"; 
     echo "<th><b>Descr</b></th>"; 
     echo "<th><b>Pk Size</b></th>"; 
     echo "<th><b>DeptNum</b></th>"; 
     echo "<th><b>Inv Units</b></th>"; 
     echo "<th><b>Qty</b></th>"; 
     echo "<th><b>UM</b></th>"; 
     echo "<th><b>Price</b></th>"; 
     echo "<th><b>Multiple</b></th>"; 
     echo "<th><b>Pack</b></th>"; 
     echo "<th><b>Cost</b></th>"; 
     echo "<th><b>Allow</b></th>"; 
     echo "</tr>"; 
     echo "</thead>"; 

     $InvSEQ = trim(odbc_result($rsSQL1, "InvSEQ")); 
     $IDTyp  = trim(odbc_result($rsSQL1, "IDTyp")); 
     $OrdCode = trim(odbc_result($rsSQL1, "OrdCode")); 
     $ItemID = trim(odbc_result($rsSQL1, "ItemID")); 
     $SkuTyp = trim(odbc_result($rsSQL1, "SkuTyp")); 
     $Descr  = trim(odbc_result($rsSQL1, "Descr")); 
     $PkSize = trim(odbc_result($rsSQL1, "PkSize")); 
     $DeptNum = trim(odbc_result($rsSQL1, "DeptNum")); 
     $InvUnits = trim(odbc_result($rsSQL1, "InvUnits")); 
     $FinQty = trim(odbc_result($rsSQL1, "FinQty")); 
     $FinUM  = trim(odbc_result($rsSQL1, "FinUM")); 
     $FinPrice = trim(odbc_result($rsSQL1, "FinPrice")); 
     $FinMult = trim(odbc_result($rsSQL1, "FinMult")); 
     $FinPack = trim(odbc_result($rsSQL1, "FinPack")); 
     $FinCost = trim(odbc_result($rsSQL1, "FinCost")); 
     $FinAllow = trim(odbc_result($rsSQL1, "FinAllow")); 

     if ($bgcolor == '#ffffff') { 

     $bgcolor = '#dddddd'; 
     } else { 

     $bgcolor = '#ffffff'; 
     } 

     echo "<tbody>"; 
     echo "<tr>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$InvSEQ</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$IDTyp</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$OrdCode</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$ItemID</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$SkuTyp</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$Descr</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$PkSize</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$DeptNum</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$InvUnits</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$FinQty</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$FinUM</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$FinPrice</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$FinMult</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$FinPack</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$FinCost</td>"; 
     echo "<td bgcolor = '$bgcolor' align = 'center'>$FinAllow</td>"; 
     echo "</tr>"; 
     echo "</tbody>"; 
     echo "</table>"; 
     echo "</div>"; 

     } 
    } 

    odbc_close($conn); 

    include($_SERVER['DOCUMENT_ROOT'] . '/footer.php'); 
} 
?> 

回答

1

這是因爲該行:

while ($row = odbc_fetch_array($rsSQL) && $row2 = odbc_fetch_array($rsSQL1))

通過使用此條件,您說「在第一個記錄集中有記錄並且第二個記錄中還有一個記錄時循環」。

問題是您的第一個記錄集只有一個記錄(您的發票之一),然後使第一個條件在第一個循環後計算爲false。

解決方案:使用單獨的循環顯示發票的項目。

+0

好的,我相信我改變它使用一個單獨的循環。我改變了我的上面的代碼,以反映我所做的改變。現在我得到了第二張表中所需的所有數據,但它將每個數據顯示爲自己的表格,而不是單獨的行。 – James

+0

我將{}隔開,我將第二個select語句移到第一個語句的下面。現在,它看起來像這樣: 語句1 聲明2 而($行= fetch1){ 表1} 雖然($ ROW1 = fetch2){ 表2} – James

+0

真棒,這樣你的建議後,我能讓一切都顯示出來。但它只是爲第一行提供一張表格,其餘的只是在頁面上的文字。我想到了一個,我在第二個while循環中有,所以它在第一行之後關閉表。感謝您的幫助。 – James

相關問題