tags:

views:

28

answers:

3

i have this

"SELECT SUM( state ) FROM `vote` WHERE id ='5'"

now when add it in php how i can do

$xx= mysql_fetch_array(mysql_query("SELECT SUM( state ) FROM `vote` WHERE id ='5'"));

is i can do it like that

echo $xx['SUM( state )'];
+7  A: 

Give SUM( state ) an alias.

SELECT SUM( state ) AS SummedState FROM `vote` WHERE id ='5'

Now, reference the alias

echo $xx['SummedState']
Paul Alan Taylor
+1  A: 

You need to use an alias in your SQL query :

"SELECT SUM( state ) as result FROM `vote` WHEREid ='5'"

Note the "as column_name" I added in the query.


And, then, you'll be able to access the "result" column from your PHP code :

echo $xx['result'];
Pascal MARTIN
+1  A: 

You can use an alias for SUM(state):

"SELECT SUM(state) AS state_sum FROM `vote` WHERE id ='5'"

Then you would be able to reference it as follows:

echo $xx['state_sum']
Daniel Vassallo