+ 1
PHP Mysql help! (Solved!!)
I am try to add up all the numbers in a column in my database! but i don't under stand how to do it. can someone explain this to me in detail please? $sql = "SELECT SUM(loss) AS 'loss_total' FROM LossTable"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<div id=info>
quot;.$row['loss_total']."</div>"; } } else { echo "0 results"; } i want to add together all the numbers in the loss column5 Respuestas
+ 2
You can easily use a + operator in your select.
For example, lets say you have 5 columns:
SELECT col1 + col2 + col3 + col4 + col5
FROM LossTable
Let me know if that's what you were seeking to do or not. I'll be more than happy to further explain if needed, or come up with another solution.
Take care!
+ 1
Netkos Ent Thank you for you answer. is there a way to do that if I am only using just loss?
+ 1
Sorry, I was on lunch at work.
So you're wanting to calculate the sum of the column rather than the row? If loss is the only column, then there isn't anything to calculate for the row.
Let me know and I have two ways you can go about it.
+ 1
your good. i am at work also. ya sorry it would be just one column(loss). Sorry still try to learn databases.
Thank you for all the help
+ 1
Netkos Ent,
I have found a solution to my problem!YA
Thank you for all your help. and i would still like to here your solutions for a better understanding when you get time.