Jaynesh Posted July 8, 2011 Share Posted July 8, 2011 Hello I'm working on something very basic. I've created a few tables with some information and I'm having them all displayed using this code. while( $i < $row = mysql_fetch_array($myfeed_query)) { echo (number will go here) echo $row['post'] . "<br>"; echo $row['username'] . "<br>"; } In each row I've also got 2 columns each containing a number. How do I subtract number1 from number2 and have the result displayed beside each query? Link to comment https://forums.phpfreaks.com/topic/241381-doing-math-from-database/ Share on other sites More sharing options...
Jaynesh Posted July 8, 2011 Author Share Posted July 8, 2011 solved it. here it is if anyone is stuck too. while( $i < $row = mysql_fetch_array($friendfeed_query)) { $number1 = $row['number1']; $number2 = $row ['number2']; $number3 = $number1 - $number2; echo $number3; echo $row['post'] . "<br>"; echo $row['username'] . "<br>"; Link to comment https://forums.phpfreaks.com/topic/241381-doing-math-from-database/#findComment-1239921 Share on other sites More sharing options...
xyph Posted July 8, 2011 Share Posted July 8, 2011 You can do it in SQL SELECT `post`, `username`, `number1`, `number2`, `number1` - `number2` as `difference` FROM `table` Link to comment https://forums.phpfreaks.com/topic/241381-doing-math-from-database/#findComment-1239922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.