<?php
@mysql_connect("127.0.0.1","root","1s#876#$#$%Ss2")or die; //链接数据库
@mysql_select_db("gamedb")or die; //选择数据库
@mysql_query("set names 'utf8'");
$query = @mysql_query("select * from role_data")or die; //查询‘yonghu’表中的所有记录
echo "<table border=1><tr align=center><th>ID</th><th>角色</th><th>对应帐号</th><th>等级</th><th>上线</th><th>下线</th><th>钻石</th></tr>";
$n=0;
while ($row = mysql_fetch_array($query)) //遍历‘yonghu’表中的数据,并形成数组
{
$role_id = $row['role_id']; //使用键获取数组中对应的值
$role_name = $row['role_name'];
$account_id = $row['account_id'];
$level = $row['level'];
$login_time = $row['login_time'];
$logout_time = $row['logout_time'];
$bag_yuanbao = $row['bag_yuanbao'];
echo "<tr>";
echo "<td>{$role_id}</td>"; //按照数据表的列在表格里输出对应数据
echo "<td>{$role_name}</td>";
echo "<td>{$account_id}</td>";
echo "<td>{$level}</td>";
echo "<td>{$login_time}</td>";
echo "<td>{$logout_time}</td>";
echo "<td>{$bag_yuanbao}</td>";
echo "</tr>";
$n++;
/* if($n>14){
return;
}*/
}
echo "<table>";
?>
你好,你得在 SQL语句中,加上排序 ,如 select * from role_data order by login_time 这是按时间排序 如 select * from role_data order by role_id 这是按ID排序
排序当然是通过SQL,order by来实现的。select * from 表 order by 字段(如ID)desc则为倒叙。把desc改为asc则为顺序,很简单很基础得sql语法。
select * from 表 order by 字段(如ID)desc则为倒叙。把desc改为asc则为顺序