title: PHP MYSQL PDO SUM of columns
body: <p>I'm new to php and I've searched for the past hour and read all the documentation I could find and nothing is helping. I have a table that has a bunch of rows of data. I'm trying to pick one column from the whole table and add them all together. Here is what I got. All this tells me is how many rows there are that match my query, not the total sum of column I want. Any help is appreciated.</p>
  
  <pre><code>$res1 = $db-&gt;prepare('SELECT sum(distance) FROM trip_logs WHERE user_id = '. $user_id .' AND status = "2"');
  $res1-&gt;execute();
  $sum_miles = 0;
  while($row1 = $res1-&gt;fetch(PDO::FETCH_ASSOC)) {
  $sum_miles += $row1['distance'];
  }
  echo $sum_miles;
  </code></pre>