PHP显示名称相同的最后数据

时间:2014-10-30 08:54:27

标签: php mysql

如何显示名称相同的最后数据。我认为我的结果是错误的。请帮我解决一下。谢谢

$SearchQ = "SELECT * FROM tblperson where Id = ".$_GET['Id'];
$SearchResult = mysql_query($SearchQ,$link);
$StaffRec = mysql_fetch_array($SearchResult);
<input type="text" name="txtPastDate" id="txtPastDate" value="<?php 
    $result = mysql_query("SELECT * from tblvisit order by tblvisit.Id desc limit 1 where tblvisit.PatientName = $StaffRec['Name']");
    while($row = mysql_fetch_assoc($result))
    {
        echo $row['VisitDate'];
    }
    mysql_free_result($result);
?>"/>

1 个答案:

答案 0 :(得分:0)

您的查询将是

$result = mysql_query("SELECT * from tblvisit 
                       WHERE tblvisit.PatientName = '".$StaffRec['Name']."'
                       ORDER BY tblvisit.Id desc limit 1");

仅在condition后,您必须应用order