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 $show=($i!=$page)?"$i":"$i";
- Echo $show." ";
- }
- ?>
复制代码
输出结果:
|
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31