php怎么获取数据库最后几条数据

2024-11-15 20:24:15
推荐回答(2个)
回答1:

$con = mysql_connect("localhost","root","");//连接数据库
mysql_select_db("btxiazai",$con);//选择数据库
mysql_query("set names utf8");
$sql = "select * from persons order by id desc limit 2";//获取persons中的数据,并按id倒叙排列,取其中两条
$get = mysql_query($sql);//执行sql
while($result = mysql_fetch_assoc($get)){//取回数据

}

回答2:

select * from table order by id desc limit 2