1, get table data 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";
- }
- ?>
Copy code
Output result:
2, get table data 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";
- }
- ?>
Copy the code
output result:
3, Get table data 03
-
-
mysql_connect("localhost","dev","mysql");
- mysql_select_db("dev");
-
- $result=mysql_query("select id,name from tb_test") ;
- print "
";- print "
encoding | ";
- print "
Name | ";
-
- while ($row = mysql_fetch_array($result))
- {
- print "
";- print "
{$row[" id"]} | ";
- print "
{$row["name"]} | ";
- }
- print "
";
- ?>
Copy the code
output result:
4. Get data paging 04
-
-
$page=isset($_GET['page'])?intval($_GET['page']):1;
- $num=3; //Display 3 per page Piece of data
- $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; //Get the value of the first parameter of limit. If the first page is (1-1)*10=0, the second page is (2 -1)*10=10.
- $info=mysql_query("select id,name from tb_test limit $offset,$num");
- print "
";- print "
Encoding | ";
- print "
Name | ";
- While($row=mysql_fetch_array($info)){
- print "
" ;- print "
";- print "
{$row["id"]} | ";
- print "
{$row["name"]} | ";
- }//Display data
- print "
";
- For($i=1;$i $show=($i!=$page)?"$i":"";
- Echo $show." ";
- }
- ?>
Copy the code
output result:
|