Forum Moderators: coopster

Message Too Old, No Replies

SUM help needed

         

gswahla

9:22 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



I have created a mysql db and table....I am able to read the values into a php webpage, but I want to be able to read the totals of the columns into the page as well....

at the moment I am trying:

$sql="SELECT SUM($counter) FROM milton";
$mysql_result=mysql_query($sql,$connection);
echo "$mysql_result";

but am gettin nothing....

any ideas?

hakre

9:33 pm on Jul 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi gswahla, welcome to webmasterworld [webmasterworld.com].

$sql="SELECT SUM($counter) FROM milton";

change $counter to counter and test again. that might be the solution. don't mix sql with php vars that way ;).

- hakre

gswahla

9:49 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



I get the following:

Resource id #3

what does that mean?!?

hakre

12:53 am on Jul 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that's a good, now everything went right. you can use this resource id (the var) to request the data from the mysql server, the [url=php.net/mysql_fetch_array]mysql_fetch_array()[/url] function needs it as parameter for example.

$array = mysql_fetch_array($mysql_result);
echo $array[0];

this piece of code should output the SUM in your query.

-hakre

gswahla

6:54 am on Jul 18, 2003 (gmt 0)

10+ Year Member



:) thanks so much, it works!