gpt4 book ai didi

php - 使用 while 循环时未显示数据库的第一个结果

转载 作者:行者123 更新时间:2023-11-29 19:06:17 25 4
gpt4 key购买 nike

我正在创建一个 PHP 脚本来根据 SQL 中存储的数据生成报告,查询在这里:

$sql = $adb->query("SELECT firstname, lastname, policynumber, isatype, isaname, startdate, unitvalue, numberofunits, currentamount, date, newunitvalue, newnumberofunits, newcurrentamount
FROM vtiger_isa, vtiger_addisa, vtiger_contactdetails
WHERE vtiger_isa.relatedclient = vtiger_addisa.addrelatedclient
AND vtiger_addisa.addrelatedclient = vtiger_contactdetails.contactid
AND vtiger_isa.relatedclient = $clientid
AND vtiger_isa.policynumber = $polnum
AND vtiger_addisa.addrelatedclient = $clientid
AND vtiger_addisa.newpolicynumber = $polnum
ORDER BY date ASC"
);

这表现得很好,因为我已经使用 print_r($sql); 进行了测试,并且我想要的结果就在那里。尽管当我循环查看结果时它们没有显示。我已经用不同的 clientid 进行了测试,第一个结果似乎错过了。

<b> New Figures:</b>
<table style="width:100%">
<tr>
<th>Date</th>
<th>Unit Value (P)</th>
<th>Number of Units</th>
<th>Total Value (£)</th>
</tr>
<?php
while ($sql->fetchInto($row)) {
?>
<tr>
<td><?php echo $row['date'];?></td>
<td><?php echo $row['newunitvalue'];?></td>
<td><?php echo $row['newnumberofunits'];?></td>
<td><?php echo $row['newcurrentamount'];?></td>
</tr>
<?php
}?>
</table>
</body>
</html>

最佳答案

我没有使用fetchInto()方法。我使用以下示例:

<?php
$sql = $adb->query("...");

foreach($sql as $row){
?>
<tr>
<td><?php echo $row['date'];?></td>
<td><?php echo $row['newunitvalue'];?></td>
<td><?php echo $row['newnumberofunits'];?></td>
<td><?php echo $row['newcurrentamount'];?></td>
</tr>
<?php
}
?>

这每次都有效。尝试一下。

关于php - 使用 while 循环时未显示数据库的第一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43478880/

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