gpt4 book ai didi

php - mysql_fetch_row 循环不返回第一组结果

转载 作者:行者123 更新时间:2023-11-29 13:30:37 26 4
gpt4 key购买 nike

我试图返回一组由开始和结束 session 变量决定的值。该代码可以工作,但由于某种原因不会从初始变量返回任何内容。

例如如果输入范围 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"); } }?>

最佳答案

正在运行的查询包含此子句:

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

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

关于php - mysql_fetch_row 循环不返回第一组结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19518881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com