我创建了一个用于显示报告的查询。查询从几个不同的表中获取数据很好,虽然我无法弄清楚如何在表中回显多个匹配值。例如,表vtiger_addisa有多个newcurrentamount,我需要显示它。
$sql = $adb->query("SELECT *
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 = $relatedclient
AND vtiger_isa.policynumber = $policynumber");
//Uncomment lines below for testing sql
//echo $sql;
//exit;
while ($sql->fetchInto($row)) {
// Assuming DB's default fetchmode is DB_FETCHMODE_ORDERED
echo $row['firstname'] . "\n";
echo $row['lastname'] . "\n";
echo $row['policynumber'] . "\n";
echo $row['newcurrentamount'] . "\n";
echo $row['newcurrentamount'] . "\n";
echo $row['currentamount'] . "\n";
exit;
}
答案 0 :(得分:1)
您可以获得多行结果,如下所示。
global $adb;
$sql = $adb->query("SELECT * 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 = $relatedclient
AND vtiger_isa.policynumber = ?");
$params = array($policynumber);
$result = $adb->pquery($query, $params);
$noOfRows = $db->num_rows($result);
for($i=0; $i<$noOfRows; ++$i) {
$firstname = $db->query_result($result, $i, "firstname");
$lastname = $db->query_result($result, $i, "lastname");
$policynumber = $db->query_result($result, $i, "policynumber");
$newcurrentamount = $db->query_result($result, $i, "newcurrentamount");
$currentamount = $db->query_result($result, $i, "currentamount");
}
答案 1 :(得分:0)
使用'as'运算符
select newcurrentamount as a, newcurrentamount as b from vtiger_addisa
P.S-尝试避免'*'并仅使用必要的列。