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 CodeOutput 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 CodeOutput 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 "
- Print "
- Print "
- Print "
- }
- while ($row = Mysql_fetch_array ($result))
- {
- Print "
- Print "
";
code | ";
name | ";
";
{$row ["id"]} | ";
{$row ["name"]} | ";
";
- ?>
Copy CodeOutput: 4, get data page 04
- $page =isset ($_get[' page ')? Intval ($_get[' page ')): 1;
- $num = 3; Show 3 data per page
- $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; Gets the value of the first parameter of the limit, assuming that the first page is (1-1) *10=0, and the second page is (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 "
- }//Displaying data
- Print "
- Print "
";
code | ";
name | ";
";
";
{$row ["id"]} | ";
{$row ["name"]} | ";
";
- for ($i =1; $i <= $pagenum; $i + +) {
- $show = ($i! = $page)? " $i ":"$i";
- Echo $show. " ";
- }
- ?>
Copy CodeOutput Result: |