読者です 読者をやめる 読者になる 読者になる

PHPやるお

うおおおおおおおおお!

PHPを使ってMySQLのデータベース内のテーブルすべてをUNION式に変換しながらループで取り出す(原始的な方法)

参考にしたサイト

SQL UNIONでつなげ複数テーブルを読み込む
SQL文をPHP内で書くときの注意 - omnioo lab.
while文 - 繰り返し処理 - PHP入門

結論

MySQLの文法でwhileする方法がわからなかった。代替案を実行した。

以下のようなものが出力される。

SELECT title, rank, name FROM $tb_name_list[0] UNION 
SELECT title, rank, name FROM $tb_name_list[1] UNION 
SELECT title, rank, name FROM $tb_name_list[2] UNION 
SELECT title, rank, name FROM $tb_name_list[3] UNION 
SELECT title, rank, name FROM $tb_name_list[4] UNION 
SELECT title, rank, name FROM $tb_name_list[5] UNION 
SELECT title, rank, name FROM $tb_name_list[6] UNION 
SELECT title, rank, name FROM $tb_name_list[7] UNION 
SELECT title, rank, name FROM $tb_name_list[8] UNION 
SELECT title, rank, name FROM $tb_name_list[9] UNION 
SELECT title, rank, name FROM $tb_name_list[10] UNION 
SELECT title, rank, name FROM $tb_name_list[11] UNION 
SELECT title, rank, name FROM $tb_name_list[12] UNION 
SELECT title, rank, name FROM $tb_name_list[13] UNION 
SELECT title, rank, name FROM $tb_name_list[14] UNION 
SELECT title, rank, name FROM $tb_name_list[15] UNION 
SELECT title, rank, name FROM $tb_name_list[16] UNION 
SELECT title, rank, name FROM $tb_name_list[17] UNION 
SELECT title, rank, name FROM $tb_name_list[18] UNION 
SELECT title, rank, name FROM $tb_name_list[19] UNION 
SELECT title, rank, name FROM $tb_name_list[20] UNION 
SELECT title, rank, name FROM $tb_name_list[21] UNION 
SELECT title, rank, name FROM $tb_name_list[22] UNION 
SELECT title, rank, name FROM $tb_name_list[23] UNION 
SELECT title, rank, name FROM $tb_name_list[24] UNION 
SELECT title, rank, name FROM $tb_name_list[25] UNION 
SELECT title, rank, name FROM $tb_name_list[26] UNION 
SELECT title, rank, name FROM $tb_name_list[27] UNION 
SELECT title, rank, name FROM $tb_name_list[28] UNION 
SELECT title, rank, name FROM $tb_name_list[29] UNION 
SELECT title, rank, name FROM $tb_name_list[30] UNION 
SELECT title, rank, name FROM $tb_name_list[31] UNION 
SELECT title, rank, name FROM $tb_name_list[32] UNION 
SELECT title, rank, name FROM $tb_name_list[33] UNION 
SELECT title, rank, name FROM $tb_name_list[34] UNION 
SELECT title, rank, name FROM $tb_name_list[35] UNION 
SELECT title, rank, name FROM $tb_name_list[36] UNION 
SELECT title, rank, name FROM $tb_name_list[37] UNION 
SELECT title, rank, name FROM $tb_name_list[38] UNION 
SELECT title, rank, name FROM $tb_name_list[39] UNION 
SELECT title, rank, name FROM $tb_name_list[40] UNION 
SELECT title, rank, name FROM $tb_name_list[41] UNION 
SELECT title, rank, name FROM $tb_name_list[42] UNION 
SELECT title, rank, name FROM $tb_name_list[43] UNION 
SELECT title, rank, name FROM $tb_name_list[44] UNION 
SELECT title, rank, name FROM $tb_name_list[45] UNION 
SELECT title, rank, name FROM $tb_name_list[46] UNION 
SELECT title, rank, name FROM $tb_name_list[47] UNION 
SELECT title, rank, name FROM $tb_name_list[48] UNION 
SELECT title, rank, name FROM $tb_name_list[49] UNION 
SELECT title, rank, name FROM $tb_name_list[50] UNION 
SELECT title, rank, name FROM $tb_name_list[51] UNION 
SELECT title, rank, name FROM $tb_name_list[52] UNION 
SELECT title, rank, name FROM $tb_name_list[53] UNION 
SELECT title, rank, name FROM $tb_name_list[54] UNION 
SELECT title, rank, name FROM $tb_name_list[55] UNION 
SELECT title, rank, name FROM $tb_name_list[56] UNION 
SELECT title, rank, name FROM $tb_name_list[57] UNION 
SELECT title, rank, name FROM $tb_name_list[58] UNION 
SELECT title, rank, name FROM $tb_name_list[59] UNION 
SELECT title, rank, name FROM $tb_name_list[60] UNION 
SELECT title, rank, name FROM $tb_name_list[61] UNION 
SELECT title, rank, name FROM $tb_name_list[62] UNION 

このSQL文を、PHPコード内にヒアドキュメントとしてコピペする。
UNION式は、最後の行だけは「UNION」の記述が不要なので、削除しておく。 とりあえず応急処置として。