Hello to all! :-)

I want to make a choice from several tables at the same time on the 'namber' line (the number of tables is 22, there are 4 columns in each table (id, namber, name, text).

I decided to make a UNION request, but I don’t know whether to make the request correctly or is there another more convenient and faster way?

 $namber = $_GET['namber']; require 'lib/connect.php'; $strSQL = " SELECT * FROM `g_fight` WHERE namber='$namber' UNION SELECT * FROM `g_drive` WHERE namber='$namber' UNION SELECT * FROM `g_strategy` WHERE namber='$namber' UNION SELECT * FROM `g_arcade` WHERE namber='$namber' UNION SELECT * FROM `g_azart` WHERE namber='$namber' UNION SELECT * FROM `g_cart` WHERE namber='$namber' UNION SELECT * FROM `g_classical` WHERE namber='$namber' UNION SELECT * FROM `g_headcrash` WHERE namber='$namber' UNION SELECT * FROM `g_history` WHERE namber='$namber' UNION SELECT * FROM `g_interesting` WHERE namber='$namber' UNION SELECT * FROM `g_kids` WHERE namber='$namber' UNION SELECT * FROM `g_kidsschook` WHERE namber='$namber' UNION SELECT * FROM `g_line` WHERE namber='$namber' UNION SELECT * FROM `g_logical` WHERE namber='$namber' UNION SELECT * FROM `g_pazzle` WHERE namber='$namber' UNION SELECT * FROM `g_shoot` WHERE namber='$namber' UNION SELECT * FROM `g_snake` WHERE namber='$namber' UNION SELECT * FROM `g_spaceship` WHERE namber='$namber' UNION SELECT * FROM `g_sport` WHERE namber='$namber' UNION SELECT * FROM `g_walking` WHERE namber='$namber' UNION SELECT * FROM `g_tetris` WHERE namber='$namber' UNION SELECT * FROM `g_rolier` WHERE namber='$namber' UNION SELECT * FROM `g_ontable` WHERE namber='$namber'"; $rs = mysql_query($strSQL); while($row = mysql_fetch_array($rs)) { $str = "".$row['name'].""; $NAME = str_replace(" ","",$str); $gtype="Игра";// тип (для закладки) $text="".$row['text']."";//описание mysql_close(); } 
  • replace union with union all it is faster. And so, you have no other way to go with such a database structure. A more privileged decision would be to make one common table, possibly with a "game type" column. Although it is more like the genres of games and one game may have several. then the table of games, the table of genres and the link id_gry-id_gangr come to the fore - Mike
  • Thanks union all really works faster :-) - Daniel
  • @ Daniel is not drowned with this at all, better do as advised by Mike. For what is written is wrong. Read about normal forms, how to link tables, etc. - Alexey Shimansky
  • If it's not too late (not a lot of code is written), think about changing the structure of the database. To accompany this is hell. And if you add a new genre, create a new table and edit all the scripts. yes and speed with one table would be more. - Mike
  • And instead of the stars everywhere clearly list the fields. And the very first ALTER TABLE will give you an unforgettable experience .. - Akina

0