0

我正在尝试显示两个表,它们显示了不同的数据集。第一个表只是显示发票信息的单行。第二个表显示发票中包含的所有项目。目前该页面正在正确显示第一个表格。第二张桌子是我遇到问题的地方。该表显示了我想要的所有数据。但它将每个项目显示为单独的表格,而不是表格中的行。有人可以看看我的代码,并可能帮助我找出问题所在吗?谢谢

<?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');

删除了每个公司政策的选择声明

$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>";

删除了每个公司政策的选择声明

      $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');
}
?>
4

1 回答 1

1

这是因为这一行:

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

通过使用此条件,您可以说“在第一个记录集中有记录并且如果第二个记录集中也有记录时循环”。

问题是您的第一个记录集只有一个记录(您的发票),然后在第一个循环之后使第一个条件评估为 false。

解决方案:使用单独的循环显示发票的项目。

于 2013-08-18T16:35:01.543 回答