im trying to combine two tables together, but whenever i run the program, this happens.

As you can see i've echoed out the sql statement. Here are my codes.
$queryc1 = "select sum(repeater),sum(membersigned) from sales UNION ALL select count(*) from approach;"; //DO INNERJOIN PRACTISE
$resultc1 = mysqli_query($dbconn,$queryc1);
echo "<table>
<tr>
<th>Repeater</th>
<th>Members</th>
<th>Approach</th>
</tr>";
while($row = mysqli_fetch_array($resultc1)) {
echo "<tr>";
echo "<td>" . $row['sum(repeater)'] . "</td>";
echo "<td>" . $row['sum(membersigned)'] . "</td>";
echo "<td>" . $row['count(*)'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo $queryc1;
I'd like to show count(*) as in the photo, as a third column to the genrated table.
You don't need UNION select here, instead you can use subquery:
select sum(repeater) as repeater_sum,
sum(membersigned) as membersigned_sum,
(select count(*) from approach) as approach_count
from sales;
and in PHP you use $row['repeater_sum'].. etc
When you union two or more queries together each query should have the same columns of data with same data type for example :
SELECT SUM(repeater),SUM(membersigned) FROM sales
UNION
SELECT Text1,Text2 FROM approach
Replace your query with this format
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With