当前位置:Linux教程 - Mysql - 将MYSQL数据库导入到HTML表格

将MYSQL数据库导入到HTML表格



         将MYSQL数据库导入到HTML表格

    $dbname = “test“; $loginname = “user“; $loginpass = “password“; $dbhost = “localhost“;

    echo(‘‘); echo(‘

    ‘); echo(“Database $dbname“);
    $id_link = @mysql_connect($dbhost, $loginname, $loginpass);

    $tables = mysql_list_tables($dbname, $id_link);

    $num_tables = mysql_num_rows($tables);

    // store table names in an array $arr_tablenames[] = ‘‘;

    // store number of fields per table(index 0,1,2..) in an array $arr_num_fields[] = ‘‘; for ($i=0; $i < $num_tables; $i++) { $arr_tablenames[$i] = mysql_tablename($tables, $i); $arr_num_fields[$i] = mysql_num_fields(mysql_db_query($dbname, “select * from $arr_tablenames[$i]“, $id_link)); }

    // store field names in a multidimensional array: // [i] == table number, [ii] == field number for that table for ($i=0; $i < $num_tables; $i++) { for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) { $result = mysql_db_query($dbname, “select * from $arr_tablenames[$i]“, $id_link); $hash_field_names[$i][$ii] = mysql_field_name($result, $ii); } }

    for ($i=0; $i < $num_tables; $i++) { echo(“

    Table $arr_tablenames[$i]
    “); echo(‘‘); $result = mysql_db_query($dbname, “select * from $arr_tablenames[$i]“, $id_link); for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) { echo(“ “); echo $hash_field_names[$i][$ii]; echo(“ “); } echo(“
    “); $number_of_rows = @mysql_num_rows($result); for ($iii = 0; $iii < $number_of_rows; $iii++) { $record = @mysql_fetch_row($result); for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) { echo(“ “); echo $record[$ii]; echo(“ “); } echo(“
    “); } echo(“ “); }


    echo(‘‘); ?>

    原作者:Tudor
    发布人:Crystal 来自:中国超级unix联盟