Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.