Three methods for displaying MySQL data in PHP are described in detail. Yesterday's program was like this :? Php $ linkmysql_connect (localhost, root, previous administrator password); if (! $ Link) echo no connection successful !; Elseecho connection successful !; The program of mysql_select_db yesterday is as follows:
$ Link = mysql_connect ("localhost", "root", "previous administrator password ");
If (! $ Link) echo "no connection successful! ";
Else echo "connection successful! ";
Mysql_select_db ("infosystem", $ link );
$ Q = "SELECT * FROM info ";
Mysql_query ("set names GB2312 ");
$ Rs = mysql_query ($ q, $ link );
If (! $ Rs) {die ("Valid result! ");}
Echo"
";Echo"
Department name |
Employee Name |
PC name |
";While ($ row = mysql_fetch_row ($ rs) echo"
$ Row [1] |
$ Row [2] |
$ Row [3] |
";Echo"
";
Mysql_close ($ link );
?>
The red part in the program is the key to displaying MySQL data. Here, you can use the other two methods to replace the red part and achieve the same effect.
While ($ row = mysql_fetch_object ($ rs) echo"$ Row-> depart$ Row-> ename$ Row-pcname";
While ($ row = mysql_fetch_array ($ rs) echo"$ Row [depart]$ Row [ename]$ Row [pcname]";
Briefly describe:
A row of data columns returned using the mysql_fetch_row () method are stored in an array unit, and the offset starts from 0. For example, to return the data of the second field, you should write $ row [1] instead of $ row [2].
Similar to mysql_fetch_array () and mysql_fetch_row (), the returned data is stored in an array. The difference is that we should use the field to access the array instead of using the offset, for example, $ row [depart].
Mysql_fetch_object () does not return an array but an object. we should use the operation method of the object to read data, for example, $ row-> depart.
You can select a method to read MySQL data instead of the red part in the program as needed.
Why :? Php $ link = mysql_connect ("localhost", "root", "previous administrator password"); if (! $ Link) echo "no connection successful! "; Elseecho" connection successful! "; Mysql_select_db...