我正在创建一个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>
答案 0 :(得分:0)
我没有使用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
}
?>
每次都有效。尝试一下。