我有一个现有的结果页面,它查询一个表并通过如下循环显示表中的匹配记录:
<table class="WADAResultsTable" border="0" cellpadding="0" cellspacing="0">
<tr>
<th class="WADAResultsTableHeader">clientID:</th>
</tr>
<?php do { ?>
<tr class="<?php echo $WARRT_AltClass1->getClass(true); ?>">
<td class="WADAResultsTableCell">
<?php echo($row_WADAsys_visits['clientID']); ?></td>
</tr>
<?php } while ($row_WADAsys_visits = mysql_fetch_assoc($WADAsys_visits)); ?>
</table>
问题是 clientID 对查看者没有任何意义。我创建了一个记录集,它与表 sys_client 执行连接以获取名称。
mysql_select_db($database_redcross, $redcross);
$query_idToClient = "SELECT clientLName, clientFName FROM sys_client LEFT JOIN sys_visits USING (clientID)";
$idToClient = mysql_query($query_idToClient, $redcross) or die(mysql_error());
$row_idToClient = mysql_fetch_assoc($idToClient);
$totalRows_idToClient = mysql_num_rows($idToClient);
如何更改循环以回显在该 JOIN 中找到的与循环中已经回显的预先存在的 clientID 匹配的 clientFName 和 clientLName?
这是 sys_visits 代码:
$maxRows_WADAsys_visits = 25;
$pageNum_WADAsys_visits = 0;
if (isset($_GET['pageNum_WADAsys_visits'])) {
$pageNum_WADAsys_visits = $_GET['pageNum_WADAsys_visits'];
}
$startRow_WADAsys_visits = $pageNum_WADAsys_visits * $maxRows_WADAsys_visits;
mysql_select_db($database_redcross, $redcross);
$query_WADAsys_visits = "SELECT pid, clientID, address, city, state, zip, latitude, longitude, FROM sys_visits ORDER BY pid ASC";
setQueryBuilderSource($query_WADAsys_visits,$WADbSearch1,false);
$query_limit_WADAsys_visits = sprintf("%s LIMIT %d, %d", $query_WADAsys_visits, $startRow_WADAsys_visits, $maxRows_WADAsys_visits);
$WADAsys_visits = mysql_query($query_limit_WADAsys_visits, $redcross) or die(mysql_error());
$row_WADAsys_visits = mysql_fetch_assoc($WADAsys_visits);
if (isset($_GET['totalRows_WADAsys_visits'])) {
$totalRows_WADAsys_visits = $_GET['totalRows_WADAsys_visits'];
} else {
$all_WADAsys_visits = mysql_query($query_WADAsys_visits);
$totalRows_WADAsys_visits = mysql_num_rows($all_WADAsys_visits);
}
$totalPages_WADAsys_visits = ceil($totalRows_WADAsys_visits/$maxRows_WADAsys_visits)-1;