TapeGun007 Posted February 17, 2019 Share Posted February 17, 2019 This might be more of a mySQL question or a PHP question, I'm not exactly sure. I have a field in my table (Deals) called "Price". All I want is the sum of that field. I tried using something like: $price += $row['Price']; This ended up as one long string, even though the database is set as a decimal number field. Then I tried doing it from mySQL like this (from what I read), but I don't think I have the full answer: foreach($stmt->query('SELECT SUM(Price) FROM Deals') as $row) { echo "<tr>"; echo "<td>Total</td>"; echo "<td> ->".$row['SUM(Price)']."</td>"; echo "</tr>"; } Anyway, if someone could just show me how to get that sum, I would greatly appreciate it because I am missing something here. Link to comment Share on other sites More sharing options...
benanamen Posted February 17, 2019 Share Posted February 17, 2019 ` Link to comment Share on other sites More sharing options...
TapeGun007 Posted February 17, 2019 Author Share Posted February 17, 2019 5 minutes ago, benanamen said: ` Uh... thanks benanamen. Heheh. I kept searching, reading, and finally found the solution: $stmt = $pdo->prepare("SELECT SUM(Price) AS sumprice FROM Deals"); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); echo $row['sumprice']; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.