I would not do it in the above way, it requires everything to be read from the database tables. It works if there are only a few rows, but if there are million rows then it would take lots of memory and lots of time to do it this way.
Instead I would do it like below (which is better but probably not the best way). Note, replace "id" in the "COUNT(id)" with your primary key for the table.
$query = "select COUNT(id) from table_a";
$count_a = mysql_query($query);
$query = "select COUNT(id) from table_b";
$count_b = mysql_query($query);
$total = $count_a + $count_b ;
print "There are $total rows in tables a and b combined";