I have two tables(table_a and table_b) combined with a UNION.
How can I check if record ist table_a.
I tried this, but not working:
$res=mysql_query("(SELECT id, added FROM table_a WHERE user_id = '".$uid."')
UNION
(SELECT id as comments, added FROM table_b WHERE user_id = '".$uid."') ORDER BY added DESC LIMIT 50");
if(!empty($rows["comments"])) // not working
It’s not working because you forgot to read the result-set:
Important:
Please don’t use
mysql_*functions, it’s deprecated (see red box) and vulnerable to sql-injection.Use PDO or MySQLi.
Update:
If you want to know from which table the result “came” you can change your query to:
Then check the value of:
$rows["came_from "]