仅当显示记录属于PHP中的表(1)时才显示记录

i have 2 tables which are join together with the help of UNION and display the records using single while loop.

problem: now the problem is i want do display records from table(1) and table(2) separately but condition is using only single while loop.

here is the SQL:`

$sql =  "(SELECT * FROM subject_first WHERE date BETWEEN '$user_from' AND '$user_to') UNION (SELECT * FROM subject_second WHERE date BETWEEN '$user_from' AND '$user_to')";

is there any way to do it?.sorry to say but i am new to PHP. any advise is appreciated.

Just add a field to both sides of the query:

(SELECT *, 'subject_first' as `table` FROM subject_first WHERE date BETWEEN '$user_from' AND '$user_to') 
UNION 
(SELECT *, 'subject_second' as `table` FROM subject_second WHERE date BETWEEN '$user_from' AND '$user_to')
ORDER BY `table` 

I added the order by part so you can insert a <br> or whatever to split the results.