PHP reads MYSQL content to a two-dimensional array and outputs $ amax = count ($ array) according to the specified column; // obtains the number of data in the array.
PHP reads MYSQL content to a two-dimensional array and outputs it by specified column
<?
$ Host = 'localhost'; // host name
$ User = 'root'; // mysql username
$ Password = ''; // mysql password
$ Database = 'doc'; // mysql database name
$ Tables = 'mclass'; // table name
$ Conn = mysql_connect ('$ host',' $ user', '$ password') or die ('database opening error ');
Mysql_select_db ('$ database ');
$ Query = 'select * from $ tables ';
$ Result = mysql_query ($ query, $ conn );
$ I = 0;
$ J = 0;
While ($ row = mysql_fetch_row ($ result )){
$ Array [$ I] [$ j] = $ row [0]. $ row [1];
$ Array2 [$ I] [$ j] = $ row [0];
$ J; // echo $ I. ','. $ j. $ row [1]. '<br> ';
If ($ j = 3 ){
$ I;
$ J = 0;
} // Else {$ j ;}
}
$ Amax = count ($ array); // Obtain the number of data in the array.
$ Rows = 2; // set the number of columns
// Start to display data
For ($ x = 0; $ x <= $ amax-1; $ x ){
For ($ y = 0; $ y <= $ rows; $ y ){
Echo '<a href = '. $ array2 [$ x] [$ y]. '> '. $ array [$ x] [$ y]. '</a> | ';
}
Echo '<p> ';
}
/*
The result is
Aaa | bbb | ccc
Ddd | eee | fff
Lll | mmm | nnn
.....
*/
?>