2013-10-22 3 views
0

시작 변수와 끝 변수에서 결정된 값 집합을 반환하려고합니다. 코드가 작동하지만 어떤 이유로 초기 변수에서 아무 것도 반환하지 않습니다.mysql_fetch_row 루프가 첫 번째 결과 집합을 반환하지 않습니다.

범위 ABC001에서 ABC010을 입력하면 ABC002 - ABC010의 모든 값이 반환되고 ABC001의 값은 표시되지 않습니다.

내 쿼리는 SQL에 직접 입력 할 때 완벽하게 작동하며 결과 세트를 이미 호출했다고 생각하지 않으므로 첫 번째 결과 집합이 반환되지 않습니다.

추신 : 나는 많은 기능을 사용하고 있지만 더 이상 사용되지 않는 것으로 알고 있습니다. 그러나 이것은 꽤 오래된 사이트이며 역사적으로는 아직 다시 쓸 준비가되어 있지 않습니다.

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

하지만 BETWEEN 문자열을하고는 비교가 아닌 LIKE : 실행중인

<?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"); } }?> 
+0

새로운 코드에서 mysql_ * 함수를 사용하지 마십시오. 더 이상 사용되지 않습니다. 대신 [PDO] (http://www.php.net/manual/en/book.pdo.php) 또는 MySQLi를 사용하십시오. – Subin

+0

잠시 동안이 API를 사용하지 않았지만'mysql_data_seek ($ no)'행을 수행해야한다는 것을 기억합니까? 아니면 mysql_fetch_row가 반복합니까? – foobar123foofoo

+0

@Subin 필자는 사용했던 많은 함수가 사용되지 않았 음을 알고 있습니다.하지만이 함수는 역사적으로 오래된 사이트이므로 아직 다시 작성할 준비가되어 있지 않습니다. 건배 팁 : – Funk247

답변

1

쿼리는이 조항이 포함되어 있습니다. alpahbetical 순서로, ABC001ABC001 % 앞에옵니다. 따라서 예상 한 첫 번째 행은 쿼리와 일치하지 않습니다.

+0

그게 전부 야! 와일드 카드가 비교에 영향을 줄 것이라고는 생각하지 못했습니다. 고마워요 :) – Funk247

관련 문제