Result in decimals?
Alright so I've been trying to make two values in two different tables add
up to one number. Its for posting and comments how many a user has done.
The .$Author['id']. reads from another php file and is fine how it is.
When I use the code below it all works but the numbers are in decimals. So
if $result has a value of 4 and $result2 is 2 it would come up saying 0.6.
I have made sure that there is nothing wrong with the results or num_rows
by replacing the echo with echo "$num_rows"; and it comes up with the
right result. But why do when I try to add these together they become a
decimal?
$link = mysql_connect("--------", "---------", "--------");
mysql_select_db("--------", $link);
$result = mysql_query("SELECT * FROM post_threads WHERE author =
'".$Author['id']."'", $link);
$num_rows = mysql_num_rows($result);
$result2 = mysql_query("SELECT * FROM post_comments WHERE userid =
'".$Author['id']."'", $link);
$num_rows2 = mysql_num_rows($result2);
$a = array(".$num_rows." + ".$num_rows2.");
echo "" . array_sum($a) . "\n";
?>
No comments:
Post a Comment