how to create a dinamic query to all tables in a database php mysql

hello guys i have this query and others similar in a file php mysql:

$laps = "select sum(laps) totallaps
                                    from
                                    (
                                        select laps
                                        from w_silverstone24_25
                                        where steamid='.................'
                                        union all
                                        select laps
                                        from s_monza2024
                                        where steamid='................'
                                        (and more more more)
                                    ) t
                                ";
$resultlaps = $mysqli->query($laps);
$rowlaps = $resultlaps->fetch_assoc();
$valuelaps = $rowlaps["totallaps"];

i want to creat a dinamic query so when i add a new table in my database the results will sum automatically… now i have to add manually the code to interrogate the new tables…
how i have to do? the database is online not on my pc.