title: Change sprintf into simple UNION
body: <pre><code>$STH_1 = $DBH_R-&gt;query("SELECT table_name                        
                           FROM information_schema.tables                        
                          WHERE table_name                        
                           LIKE 'v_c_ei\_9%'
                           ");
  $stmts_1 = array();
  
  while (($row_1 = $STH_1 -&gt; fetch_assoc()) !== null){
  
  $table_name = $row_1['table_name'];
  $stmts_1[] = sprintf("SELECT *  
                          FROM $table_name
                         WHERE (ei_code = '1117') AND (DAY(date_time) != '00') 
  
                       "); 
  
  } 
  
  $stmt_1 = implode("\nUNION\n", $stmts_1);  
  $stmt_1 .= "\nORDER BY date_time ASC";  
  
  $STH_5_2 = $DBH_R-&gt;query($stmt_1);
  
  while (($row_5_2 = $STH_5_2 -&gt; fetch_assoc()) !== null){
  </code></pre>
  
  <p>OK, the script above is working ok. But, I want (must) change its functionality. I must do selection before UNION (something like ORDER BY ... LIMIT) but I know - this is not working. The solution is to change sprintif into UNION &amp; UNION &amp; UNION ... But the problem is - we don't know how much tables we have.</p>
  
  <p>The table names from the first query looks like</p>
  
  <pre><code>v_c_ei_9001
  v_c_ei_9002
  ..........
  v_c_ei_9030
  ..........
  ect.
  </code></pre>
  
  <p>Than the q: how change the sprintif (and maybe array $stmts_1 too) from abowe into the UNION in situation when we don't know how much tables we have?
  thnks</p>