1.获取表数据01
mysql_connect("localhost","dev","mysql");
mysql_select_db("dev");
$result=mysql_query("select id,name from tb_test");
while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
print_r($row);echo "
\n";
}
?>
输出结果如下:
2.获取表数据02
mysql_connect("localhost","dev","mysql");
mysql_select_db("dev");
$result=mysql_query("select id,name from tb_test");
while($row=mysql_fetch_object($result)){
echo "ID:" .$row->id." text: ".$row->name."
\n";
}
?>
3.获取表数据03
mysql_connect("localhost","dev","mysql");
mysql_select_db("dev");
$result=mysql_query("select id,name from tb_test");
print "";
print "编码 | ";
print "名字 | ";
while ($row = mysql_fetch_array($result))
{
print "";
print "{$row["id"]} | ";
print "{$row["name"]} | ";
}
print "
";
?>
4.获取数据分页04
$page=isset($_GET['page'])?intval($_GET['page']):1;
$num=3; //每页显示3条数据
$db=mysql_connect("localhost","dev","mysql");
$select=mysql_select_db("dev",$db);
$total=mysql_num_rows(mysql_query("select id,name from tb_test"));
$pagenum=ceil($total/$num);
If($page>$pagenum || $page == 0){
Echo "Error : Can Not Found The page .";
Exit;
}
$offset=($page-1)*$num; //获取limit的第一个参数的值,假如第一页则为(1-1)*10=0,第二页为(2-1)*10=10。
$info=mysql_query("select id,name from tb_test limit $offset,$num");
print "";
print "编码 | ";
print "名字 | ";
While($row=mysql_fetch_array($info)){
print "";
print "
";
print "{$row["id"]} | ";
print "{$row["name"]} | ";
}//显示数据
print "
";
For($i=1;$i<=$pagenum;$i++){
$show=($i!=$page)?"$i":"$i";
Echo $show." ";
}
?>
阅读(9384) | 评论(0) | 转发(1) |