- I have two statements
a.
while (($row_1 = $STH_1 -> fetch_assoc()) !== null){
$table_name = $row_1['table_name'];
$stmts_1[] = sprintf("
SELECT *
FROM $table_name
WHERE date_time = $today_date ");
}
$stmt_1 = implode("\nUNION\n", $stmts_1);
$stmt_1 .= "\nORDER BY date_time ASC";
$STH_5_2 = $DBH_R->query($stmt_1);
while (($row_5_2 = $STH_5_2 -> fetch_assoc()) !== null) { }
b.
$STH_e = $DBH_R->query("
SELECT *
FROM $table_name_2
WHERE date_time = $today_date ");
while (($row_e = $STH_e -> fetch_assoc()) !== null) { }
- the source colums for query 1 and query 2 are differents
- one column are similar -> date_time, but TIME(date_time) are different, DATE(date_time) will be the same
- all I must merge into one list (ORDER BY TIME(date_time) ASC) to make source for ticker script
Q: how to merge this two statements? or maybe this two queries?
//------------------------------------------------------------- update - create table statement
table for query 1 - this type near 30 tables
CREATE TABLE IF NOT EXISTS
v_c_ei_9001
(id
int(11) unsigned NOT NULL AUTO_INCREMENT,ei_code
int(10) NOT NULL DEFAULT '0',date_time
datetime NOT NULL DEFAULT '0000-00-00 00:00:00',index_year
varchar(10) NOT NULL DEFAULT 'ndnc',index_period
varchar(10) NOT NULL DEFAULT 'nd',index_period_2
varchar(10) NOT NULL DEFAULT 'nd',index_unit
varchar(10) NOT NULL DEFAULT 'nd',index_comment
text NOT NULL,PRIMARY KEY (
id
), KEYdate_time
(date_time
) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=608 ;table for query 2 - this type is only one
CREATE TABLE IF NOT EXISTS
v_c_e
(id
int(11) unsigned NOT NULL AUTO_INCREMENT,country_code
int(10) NOT NULL DEFAULT '0',country_name
varchar(50) NOT NULL DEFAULT 'ndnc',date_time
datetime NOT NULL DEFAULT '0000-00-00 00:00:00',event_title
varchar(100) NOT NULL DEFAULT 'ndnc',event_released
int(10) NOT NULL DEFAULT '0',event_comment
varchar(500) NOT NULL DEFAULT 'ndnc',PRIMARY KEY (
id
) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=168 ;
brgs
//--------------------------------------------------- UPDATE 2
pre-query code // from all tables in the dbase we query only tables with names like v_c_ei_9xxx
$STH_1 = $DBH_R->query("SELECT table_name
FROM information_schema.tables
WHERE table_name
LIKE 'v_c_ei\_9%'
");
$stmts_1 = array();
while (($row_1 = $STH_1 -> ..... // as above
$table_name = $row_1['table_name'];
indicates a BIG, BIG trouble. – Your Common Sense