0

我试图返回一组从开始和结束会话变量决定的值。该代码有效,但由于某种原因没有从初始变量返回任何内容。

例如,如果输入范围 ABC001 到 ABC010,则返回 ABC002 - ABC010 中的所有值,则 ABC001 中不会出现任何内容。

我的查询在直接输入 SQL 时运行良好,而且我认为我还没有调用结果集,那么为什么第一组结果没有返回?

PS 我知道我使用过的很多功能已经/正在被弃用,但从历史上看,这是一个相当古老的网站,我还没有准备好重新编写它。

<?php
  require_once("includes/header2.php");
  $title = "Box Contents";
  require_once("includes/head2.php");
  isLoggedIn();

  // Catch session variables
  $_SESSION['boxidStart'] = $_POST['boxContentsStart'];
  $_SESSION['boxidEnd'] = $_POST['boxContentsEnd'];

  // Define them as named variables for ease of use
  $boxidStart = $_SESSION['boxidStart'];
  $boxidEnd = $_SESSION['boxidEnd'];

  // Box selection query
  $sql = mysql_query ("SELECT boxId, fileNumber, dateEntered, destroyDate, invoiceStatus, invoiceDate FROM fields WHERE boxId BETWEEN '$boxidStart%' AND '$boxidEnd%' ORDER BY boxId ASC");

  // SELECT Business
  $companyName = mysql_query("SELECT business from fields LEFT JOIN users ON fields.CompanyId = users.Id WHERE boxId LIKE '$boxidStart%'");
  $cn = mysql_fetch_row($companyName);
  $no = 1;

  if (!$boxidStart) {
  ?>
  <div class="clearfix"></div>
  <div>
  <h2>You need to enter some text to search for!</h2>
  <p>Please try again.</p>
  <?php
    require_once("includes/footer.php");
  } else {
    if (escape($boxidStart))
  {
  ?>
  <div class="clearfix"></div>
  <div>
  <h2 style="float:left;">Files Entered from range box <?php echo $boxidStart ?> to box <?php echo $boxidEnd ?></h2>
  <!-- company name -->
  <h2 style="float:right"><?php echo $cn[0] ?></h2>
  <div>
  <table class="results" cellpadding="3" cellspacing="0" border="1" width="100%">
    <tbody align="left">
    <tr>
        <th>No.</th>
        <th>Box No.</th>
        <th>File Number</th>
        <th>Date Entered</th>
        <th>Destroy Date</th>
        <th>Invoicing</th>
     </tr>
<?php

while ($row = mysql_fetch_row($sql)) {
    echo "<tr valign='middle' class='row'>
          <td width='5%' class='company'>", $no++ ,"</td>
          <td width='5%' class='company'>", $row[0] ,"</td>
          <td width='30%' class='company'>", $row[1],"</td>
          <td width='12.5%' class='datein'>", $new_date = date('d/m/Y', strtotime($row[2])), "</td>
          <td width='12.5%' class='filenotes'>", $new_date = date('d/m/Y', strtotime($row[3])), "</td>";

    // There must be a check in the history_files table to see if there is an entry for this fileNumber
    // If there is an entry for this file number then it means that the file has already been in the system and the invoice has been paid
    $sqlReturn = mysql_query ("SELECT fileNumber FROM history_files WHERE fileNumber = '$row[1]'");


    $result = mysql_fetch_array($sqlReturn);
    //var_dump($sqlReturn);
    if ($result) {
        // If the result is true the the text "Invoice has been paid"
        echo "<td width='35%' class='filenotes'>Invoice already paid</td></tr>";
    } else {
        // If the result is false the the text "Invoice Charge €25.00" plus VAT 
        echo "<td width='35%' class='filenotes'>Invoice charge €25.00 + VAT</td></tr>";
    }


    }
            //echo "<p>".mysql_num_rows($sql)." results<p>";
?>

</tbody>
</table>


<p><strong><br><br>Signed:</strong>________________________________<br><br></p>
<p><strong>Dated:</strong> <?php echo date('d/m/Y', strtotime($dateEntered)); ?></p>
<br><br>
</div>
<?php require_once("includes/foot.php"); } }?>
4

1 回答 1

1

正在运行的查询包括以下子句:

BETWEEN '$boxidStart%' AND '$boxidEnd%'

BETWEEN正在进行字符串比较,而不是LIKE. 按字母顺序,ABC001位于ABC001% 之前,因此您期望的第一行与查询不匹配。

于 2013-10-22T13:24:06.633 回答