在PHP结果中显示MySQL JOIN

时间:2012-10-11 11:20:55

标签: php mysql

我添加了一个成功在现有结果页面上执行JOIN的记录集:

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);

结果页面还查询另一个名为sys_visits的表,并显示当前的结果:

<table class="WADAResultsTable" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th class="WADAResultsTableHeader">clientID:</th>
    <th>&nbsp;</th>
  </tr>
  <?php do { ?>
    <tr class="<?php echo $WARRT_AltClass1->getClass(true); ?>">

      <td class="WADAResultsTableCell">

      <a href="sys_visits_Detail.php?pid=<?php echo(rawurlencode($row_WADAsys_visits['pid'])); ?>" ><?php echo($row_WADAsys_visits['clientID']); ?></a></td>
    </tr>
  <?php } while ($row_WADAsys_visits = mysql_fetch_assoc($WADAsys_visits)); ?>
</table>

如何从记录集中回显匹配的clientFName和clientLname,而不仅仅是id。两个表中的clientID相同。

1 个答案:

答案 0 :(得分:1)

while ($row = mysql_fetch_row($idToClient)) 
{
   echo "clientLName: " .$row[0] . "clientFName: " .$row[1];
}