在PHP中显示MySQL数据库的最后两行

时间:2014-03-12 16:33:37

标签: php mysql

我试图只显示我的表StudentInfo的最后两行中的timein和timeout列。 下面是代码:

$query = mysql_query("
    SELECT timein, timeout 
    FROM studentInfo
    WHERE name = 'Student' 
    ORDER BY time DESC
    LIMIT 2
    ")
    or die("Error querying database ".mysql_error());
while($minutes = mysql_fetch_array($query)){
  echo "timein: ".$minutes['timein']."<br />";
  echo "timeout: ".$minutes['timeout']."<br />";

1 个答案:

答案 0 :(得分:1)

试试这个,

$query = mysql_query("SELECT timein, timeout  FROM studentInfo WHERE name = 'Student'  ORDER BY id DESC LIMIT 2") or die(mysql_error());

while($minutes = mysql_fetch_assoc($query)){
  echo "timein: ".$minutes['timein']."<br />";
  echo "timeout: ".$minutes['timeout']."<br />";
}

-

尝试使用mysql mysqli,因为这个已弃用