Jump to content

[SOLVED] Get All Values In Column


majhate

Recommended Posts

Hello,

 

Lets say I have a table with the fields: ID, Color, Value

So..

 

ID - Color - Value

 

1 - Blue - 3

2 - Orange - 1

3 - Black - 4

4 - Red - 2

 

How would I get the total of the values in one varible.

so $total would = 10

I've been trying loops, but I cannot get this to work. Any sugguestions?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/85851-solved-get-all-values-in-column/
Share on other sites

This is what I have tried:

 

$query  = "SELECT choice_count FROM colors WHERE ID='$ID'";

$result = mysql_query($query);

 

while($rows = mysql_fetch_array($result, MYSQL_NUM))

{

 

$value = $rows[0];

echo $new . "<br />\n";

 

}

 

This will only display the values with a line break, I don't know how to add them up. I am not even sure if this would be the right way to do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.