Jump to content


Photo

adding up variables *SOLVED*


  • Please log in to reply
2 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 25 August 2006 - 01:21 AM

I need to get the sum of 2 query results but it won't let me add them up.

Here's what I have

<?php
$query = mysql_query("SELECT name FROM list WHERE club = '".$row['club']."' AND date = '".$row['date']."'") or die(mysql_error());
$count_result = mysql_num_rows($query);
$friends_query = mysql_query("SELECT SUM(number) FROM list WHERE club = '".$row['club']."' AND date = '".$row['date']."'") or die(mysql_error());
$friends_count = mysql_fetch_array($friends_query);
$friends_count = $friends_count + $count_result;
?>

and I get this error Fatal error: Unsupported operand types.

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 25 August 2006 - 01:25 AM

change:

$friends_count = mysql_fetch_array($friends_query);

to

$friends_count = mysql_result($friends_query, 0);

http://www.php.net/mysql_result

#3 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 25 August 2006 - 01:35 AM

thanks worked perfectly




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users