I have two tables inside a mysql database. table_1 and table_2
Both of these tables have 4 columns for users
user_1, user_2, user_3 and user_4
Now using PHP I first want to fetch the non-null values from two tables and I use this query.
<?php
$query1 = "
select * from table_1 where user_1!='' and user_1 is not null
union all
select * from table_1 where user_2!='' and user_2 is not null
union all
select * from table_1 where user_3!='' and user_3 is not null
union all
select * from table_1 where user_4!='' and user_4 is not null
";
Then I fetch it and count the entries total = mysqli_num_rows and it gives me correct details as 3.
Similarly I do it for table_2
<?php
$query2 = "
select * from table_2 where user_1!='' and user_1 is not null
union all
select * from table_2 where user_2!='' and user_2 is not null
union all
select * from table_2 where user_3!='' and user_3 is not null
union all
select * from table_2 where user_4!='' and user_4 is not null
";
and it shows me total count as 2 which is correct.
But when I add count1 and count2
$count1 = mysqli_num_rows($data1);
$count2 = mysqli_num_rows($data2);
$total = $count1+$count2;
It shows either 1 or some weird value.Please suggest a fix

