I have managed to use some complex mysql queries (for me at least) to come up with this results set.

Array ( [0] => 200 ) Array ( [0] => 0 ) Array ( [0] => 0 ) Array ( [0] => 0 ) Array ( [0] => 0 ) Array ( [0] => 300 ) Array ( [0] => 600 ) Array ( [0] => 400 ) Array ( [0] => 500 ) Array ( [0] => 500 ) Array ( [0] => 500 ) Array ( [0] => 400 ) Array ( [0] => 0 ) Array ( [0] => 800 ) Array ( [0] => 200 ) Array ( [0] => 400 )

As you can see the results includes multiple arrays containing just one number. Is it possible for me to combine the results for all the arrays together into a total. For instance, the total here would be 4,800.

    Thanks anyway but if it were that simple I wouldn't be asking.

    Array_sum always comes back with this.

    "Warning: array_sum() [function.array-sum]: The argument should be an array"

    Standard PHP functions don't cut it with this result. I thought maybe it has something to do with that the result contains 16 different arrays.

      process through with a for_each and sum the sums

        So for a clue on how to do that should I post in the newbie area? The thing is that everything I've tried with basic PHP functions hasn't worked so far.

          you should post
          your handling of the result of that MySQL query
          and how you put row result into array
          and also your print_r(xxxx) line

          this will make it easy to help
          🙂

            Are these arrays in separate variables? Are they all items in a containing array?

            Also, why didn't you just have MySQL give you the SUM() ?

              Here's the latest. I can print the numbers but still have no idea how to show a sum. I thought this would be very simple myself. I just can't get anything to work.

              $query12 = "SELECT SUM(value) FROM value LEFT JOIN horsevalue ON horsevalue.value_id = value.id WHERE horsevalue.horse_id = $horse_id AND horsevalue.value_id = ".$row['id'];
              $result12 = mysql_query($query12) or die(mysql_error());
              while($row12 = mysql_fetch_array($result12)){

              //echo ( $row12['SUM(value)'] ) ;

              print("<pre>".print_r($row12['SUM(value)'],true)."</pre>");

              }

              Output:

              200

              300

              600

              400

              500

              500

              500

              400

              800

              200

              400

                Just to touch on this again. PHP seems to treat is as an array for everything but getting a sum. As you can see, this basic array output does not look like a typical array. Instead it is a bunch of arrays, each containing one number. I can't figure out how to derive a sum from it.

                Array ( [0] => 200 ) Array ( [0] => 0 ) Array ( [0] => 0 ) Array ( [0] => 0 ) Array ( [0] => 0 ) Array ( [0] => 300 ) Array ( [0] => 600 ) Array ( [0] => 400 ) Array ( [0] => 500 ) Array ( [0] => 500 ) Array ( [0] => 500 ) Array ( [0] => 400 ) Array ( [0] => 0 ) Array ( [0] => 800 ) Array ( [0] => 200 ) Array ( [0] => 400 )

                  try this

                  <?php
                  
                  while($row12 = mysql_fetch_array($result12)){
                       // put & save all values into array $values, for each result row
                       $values[] = $row12['SUM(value)'];
                  }
                  
                  
                  $val_sum = array_sum( $values );
                  
                  echo 'Sum: ' . $val_sum;
                  
                  echo "<pre>".print_r($values,true)."</pre>";
                  
                  ?>
                    Write a Reply...